2012-02-26 02:09:26 +01:00
|
|
|
package rocket
|
2011-10-26 08:02:47 +02:00
|
|
|
|
|
|
|
import Chisel._
|
2012-10-08 05:15:54 +02:00
|
|
|
import Node._
|
2011-10-26 08:02:47 +02:00
|
|
|
import Constants._
|
|
|
|
import Instructions._
|
2012-02-09 06:43:45 +01:00
|
|
|
import hwacha._
|
2011-10-26 08:02:47 +02:00
|
|
|
|
2012-10-16 01:29:49 +02:00
|
|
|
class ioDpathAll(implicit conf: RocketConfiguration) extends Bundle
|
2011-10-26 08:02:47 +02:00
|
|
|
{
|
2012-10-19 02:26:03 +02:00
|
|
|
val host = new ioHTIF(conf.ntiles)
|
2012-03-02 05:48:46 +01:00
|
|
|
val ctrl = new ioCtrlDpath().flip
|
2012-05-02 03:23:04 +02:00
|
|
|
val dmem = new ioHellaCache
|
2012-02-27 08:46:51 +01:00
|
|
|
val dtlb = new ioDTLB_CPU_req_bundle().asOutput()
|
2012-10-10 06:35:03 +02:00
|
|
|
val imem = new IOCPUFrontend
|
2012-01-18 19:28:48 +01:00
|
|
|
val ptbr_wen = Bool(OUTPUT);
|
2012-07-13 03:12:49 +02:00
|
|
|
val ptbr = UFix(OUTPUT, PADDR_BITS);
|
2012-02-08 08:54:25 +01:00
|
|
|
val fpu = new ioDpathFPU();
|
2012-03-02 05:48:46 +01:00
|
|
|
val vec_ctrl = new ioCtrlDpathVec().flip
|
2012-02-15 22:30:22 +01:00
|
|
|
val vec_iface = new ioDpathVecInterface()
|
2012-02-25 04:22:35 +01:00
|
|
|
val vec_imul_req = new io_imul_req
|
2012-07-13 03:12:49 +02:00
|
|
|
val vec_imul_resp = Bits(INPUT, hwacha.Constants.SZ_XLEN)
|
2011-10-26 08:02:47 +02:00
|
|
|
}
|
|
|
|
|
2012-10-16 01:29:49 +02:00
|
|
|
class rocketDpath(implicit conf: RocketConfiguration) extends Component
|
2011-10-26 08:02:47 +02:00
|
|
|
{
|
|
|
|
val io = new ioDpathAll();
|
|
|
|
|
|
|
|
val pcr = new rocketDpathPCR();
|
|
|
|
val ex_pcr = pcr.io.r.data;
|
|
|
|
|
2012-10-10 06:35:03 +02:00
|
|
|
val alu = new ALU
|
2011-10-26 08:02:47 +02:00
|
|
|
val ex_alu_out = alu.io.out;
|
2012-01-02 02:04:14 +01:00
|
|
|
val ex_alu_adder_out = alu.io.adder_out;
|
2011-10-26 08:02:47 +02:00
|
|
|
|
|
|
|
// execute definitions
|
2012-01-02 01:09:40 +01:00
|
|
|
val ex_reg_pc = Reg() { UFix() };
|
2012-02-09 10:28:16 +01:00
|
|
|
val ex_reg_inst = Reg() { Bits() };
|
|
|
|
val ex_reg_raddr1 = Reg() { UFix() };
|
2012-01-02 01:09:40 +01:00
|
|
|
val ex_reg_raddr2 = Reg() { UFix() };
|
2012-02-08 15:47:26 +01:00
|
|
|
val ex_reg_op2 = Reg() { Bits() };
|
2012-01-02 01:09:40 +01:00
|
|
|
val ex_reg_rs2 = Reg() { Bits() };
|
|
|
|
val ex_reg_rs1 = Reg() { Bits() };
|
|
|
|
val ex_reg_waddr = Reg() { UFix() };
|
|
|
|
val ex_reg_ctrl_fn_dw = Reg() { UFix() };
|
|
|
|
val ex_reg_ctrl_fn_alu = Reg() { UFix() };
|
|
|
|
val ex_reg_ctrl_sel_wb = Reg() { UFix() };
|
2012-10-17 01:32:35 +02:00
|
|
|
val ex_wdata = Bits()
|
2012-11-05 01:40:14 +01:00
|
|
|
val ex_reg_kill = Reg() { Bool() }
|
2011-11-02 01:59:27 +01:00
|
|
|
|
2011-11-02 03:05:27 +01:00
|
|
|
// memory definitions
|
2012-01-02 01:09:40 +01:00
|
|
|
val mem_reg_pc = Reg() { UFix() };
|
2012-02-09 10:28:16 +01:00
|
|
|
val mem_reg_inst = Reg() { Bits() };
|
|
|
|
val mem_reg_rs2 = Reg() { Bits() };
|
2012-01-02 01:09:40 +01:00
|
|
|
val mem_reg_waddr = Reg() { UFix() };
|
|
|
|
val mem_reg_wdata = Reg() { Bits() };
|
2012-02-09 10:28:16 +01:00
|
|
|
val mem_reg_raddr1 = Reg() { UFix() };
|
2012-01-02 01:09:40 +01:00
|
|
|
val mem_reg_raddr2 = Reg() { UFix() };
|
2012-11-05 01:40:14 +01:00
|
|
|
val mem_reg_kill = Reg() { Bool() }
|
2011-11-02 01:59:27 +01:00
|
|
|
|
2011-11-02 03:05:27 +01:00
|
|
|
// writeback definitions
|
2012-01-03 00:42:39 +01:00
|
|
|
val wb_reg_pc = Reg() { UFix() };
|
2012-02-09 10:28:16 +01:00
|
|
|
val wb_reg_inst = Reg() { Bits() };
|
|
|
|
val wb_reg_rs2 = Reg() { Bits() };
|
2012-02-25 21:21:10 +01:00
|
|
|
val wb_reg_waddr = Reg() { UFix() }
|
|
|
|
val wb_reg_wdata = Reg() { Bits() }
|
2012-03-17 02:34:40 +01:00
|
|
|
val wb_reg_dmem_wdata = Reg() { Bits() }
|
2012-02-25 21:21:10 +01:00
|
|
|
val wb_reg_vec_waddr = Reg() { UFix() }
|
|
|
|
val wb_reg_vec_wdata = Reg() { Bits() }
|
2012-02-09 10:28:16 +01:00
|
|
|
val wb_reg_raddr1 = Reg() { UFix() };
|
2012-01-03 00:42:39 +01:00
|
|
|
val wb_reg_raddr2 = Reg() { UFix() };
|
2012-02-08 13:21:05 +01:00
|
|
|
val wb_reg_ll_wb = Reg(resetVal = Bool(false));
|
2012-05-24 19:33:15 +02:00
|
|
|
val wb_wdata = Bits();
|
2011-11-02 01:59:27 +01:00
|
|
|
|
2012-05-24 19:33:15 +02:00
|
|
|
val dmem_resp_replay = Bool()
|
2012-01-02 11:51:30 +01:00
|
|
|
val r_dmem_resp_replay = Reg(resetVal = Bool(false));
|
2012-02-08 08:54:25 +01:00
|
|
|
val r_dmem_fp_replay = Reg(resetVal = Bool(false));
|
2012-01-02 01:09:40 +01:00
|
|
|
val r_dmem_resp_waddr = Reg() { UFix() };
|
2011-10-26 08:02:47 +02:00
|
|
|
|
2012-02-02 22:33:27 +01:00
|
|
|
val ex_pc_plus4 = ex_reg_pc + UFix(4);
|
2012-02-09 00:03:59 +01:00
|
|
|
val ex_branch_target = ex_reg_pc + Cat(ex_reg_op2(VADDR_BITS-1,0), Bits(0,1)).toUFix
|
2011-10-26 08:02:47 +02:00
|
|
|
|
2012-02-08 15:47:26 +01:00
|
|
|
val ex_ea_sign = Mux(ex_alu_adder_out(VADDR_BITS-1), ~ex_alu_adder_out(63,VADDR_BITS) === UFix(0), ex_alu_adder_out(63,VADDR_BITS) != UFix(0))
|
|
|
|
val ex_effective_address = Cat(ex_ea_sign, ex_alu_adder_out(VADDR_BITS-1,0)).toUFix
|
2011-10-26 08:02:47 +02:00
|
|
|
|
2012-10-10 06:35:03 +02:00
|
|
|
// hook up I$
|
|
|
|
io.imem.req.bits.invalidateTLB := pcr.io.ptbr_wen
|
|
|
|
io.imem.req.bits.currentpc := ex_reg_pc
|
|
|
|
io.imem.req.bits.status := pcr.io.status
|
|
|
|
io.imem.req.bits.pc :=
|
|
|
|
Mux(io.ctrl.sel_pc === PC_EX4, ex_pc_plus4,
|
|
|
|
Mux(io.ctrl.sel_pc === PC_EX, Mux(io.ctrl.ex_jalr, ex_effective_address, ex_branch_target),
|
|
|
|
Mux(io.ctrl.sel_pc === PC_PCR, Cat(pcr.io.evec(VADDR_BITS-1), pcr.io.evec).toUFix,
|
|
|
|
wb_reg_pc))) // PC_WB
|
2011-10-26 08:02:47 +02:00
|
|
|
|
|
|
|
// instruction decode stage
|
2012-10-10 06:35:03 +02:00
|
|
|
val id_inst = io.imem.resp.bits.data
|
|
|
|
val id_pc = io.imem.resp.bits.pc
|
|
|
|
debug(id_inst)
|
|
|
|
debug(id_pc)
|
2012-11-05 01:40:14 +01:00
|
|
|
|
|
|
|
val regfile_ = Mem(31){Bits(width = 64)}
|
2012-11-05 10:30:57 +01:00
|
|
|
def readRF(a: UFix) = regfile_(~a)
|
2012-11-05 01:40:14 +01:00
|
|
|
def writeRF(a: UFix, d: Bits) = regfile_(~a) := d
|
2011-10-26 08:02:47 +02:00
|
|
|
|
2012-10-10 06:35:03 +02:00
|
|
|
val id_raddr1 = id_inst(26,22).toUFix;
|
|
|
|
val id_raddr2 = id_inst(21,17).toUFix;
|
2011-10-26 08:02:47 +02:00
|
|
|
|
2011-11-02 01:59:27 +01:00
|
|
|
// bypass muxes
|
2012-11-05 10:30:57 +01:00
|
|
|
val id_rs1_dmem_bypass = id_raddr1 != UFix(0) &&
|
2012-03-17 02:34:40 +01:00
|
|
|
Mux(io.ctrl.ex_wen && id_raddr1 === ex_reg_waddr, Bool(false),
|
|
|
|
Mux(io.ctrl.mem_wen && id_raddr1 === mem_reg_waddr, io.ctrl.mem_load,
|
|
|
|
Bool(false)))
|
2011-10-26 08:02:47 +02:00
|
|
|
val id_rs1 =
|
2012-11-05 10:30:57 +01:00
|
|
|
Mux(id_raddr1 === UFix(0), UFix(0),
|
2012-02-08 13:21:05 +01:00
|
|
|
Mux(io.ctrl.ex_wen && id_raddr1 === ex_reg_waddr, ex_wdata,
|
2012-03-17 02:34:40 +01:00
|
|
|
Mux(io.ctrl.mem_wen && id_raddr1 === mem_reg_waddr, mem_reg_wdata,
|
2012-02-08 13:21:05 +01:00
|
|
|
Mux((io.ctrl.wb_wen || wb_reg_ll_wb) && id_raddr1 === wb_reg_waddr, wb_wdata,
|
2012-11-05 10:30:57 +01:00
|
|
|
readRF(id_raddr1)))))
|
2011-10-26 08:02:47 +02:00
|
|
|
|
2012-11-05 10:30:57 +01:00
|
|
|
val id_rs2_dmem_bypass = id_raddr2 != UFix(0) &&
|
2012-03-17 02:34:40 +01:00
|
|
|
Mux(io.ctrl.ex_wen && id_raddr2 === ex_reg_waddr, Bool(false),
|
|
|
|
Mux(io.ctrl.mem_wen && id_raddr2 === mem_reg_waddr, io.ctrl.mem_load,
|
|
|
|
Bool(false)))
|
2012-11-05 10:30:57 +01:00
|
|
|
val id_rs2 = Mux(id_raddr2 === UFix(0), UFix(0),
|
2012-02-08 13:21:05 +01:00
|
|
|
Mux(io.ctrl.ex_wen && id_raddr2 === ex_reg_waddr, ex_wdata,
|
2012-03-17 02:34:40 +01:00
|
|
|
Mux(io.ctrl.mem_wen && id_raddr2 === mem_reg_waddr, mem_reg_wdata,
|
2012-02-08 13:21:05 +01:00
|
|
|
Mux((io.ctrl.wb_wen || wb_reg_ll_wb) && id_raddr2 === wb_reg_waddr, wb_wdata,
|
2012-11-05 10:30:57 +01:00
|
|
|
readRF(id_raddr2)))))
|
2011-10-26 08:02:47 +02:00
|
|
|
|
2012-02-08 15:47:26 +01:00
|
|
|
// immediate generation
|
|
|
|
val id_imm_bj = io.ctrl.sel_alu2 === A2_BTYPE || io.ctrl.sel_alu2 === A2_JTYPE
|
|
|
|
val id_imm_l = io.ctrl.sel_alu2 === A2_LTYPE
|
|
|
|
val id_imm_zero = io.ctrl.sel_alu2 === A2_ZERO || io.ctrl.sel_alu2 === A2_RTYPE
|
|
|
|
val id_imm_ibz = io.ctrl.sel_alu2 === A2_ITYPE || io.ctrl.sel_alu2 === A2_BTYPE || id_imm_zero
|
2012-10-10 06:35:03 +02:00
|
|
|
val id_imm_sign = Mux(id_imm_bj, id_inst(31),
|
|
|
|
Mux(id_imm_l, id_inst(26),
|
2012-02-08 15:47:26 +01:00
|
|
|
Mux(id_imm_zero, Bits(0,1),
|
2012-10-10 06:35:03 +02:00
|
|
|
id_inst(21)))) // IMM_ITYPE
|
2012-02-08 15:47:26 +01:00
|
|
|
val id_imm_small = Mux(id_imm_zero, Bits(0,12),
|
2012-10-10 06:35:03 +02:00
|
|
|
Cat(Mux(id_imm_bj, id_inst(31,27), id_inst(21,17)), id_inst(16,10)))
|
2012-02-08 15:47:26 +01:00
|
|
|
val id_imm = Cat(Fill(32, id_imm_sign),
|
2012-10-10 06:35:03 +02:00
|
|
|
Mux(id_imm_l, Cat(id_inst(26,7), Bits(0,12)),
|
2012-02-08 15:47:26 +01:00
|
|
|
Mux(id_imm_ibz, Cat(Fill(20, id_imm_sign), id_imm_small),
|
2012-10-10 06:35:03 +02:00
|
|
|
Cat(Fill(7, id_imm_sign), id_inst(31,7))))) // A2_JTYPE
|
2012-02-08 15:47:26 +01:00
|
|
|
|
2012-03-17 02:34:40 +01:00
|
|
|
val id_op2_dmem_bypass = id_rs2_dmem_bypass && io.ctrl.sel_alu2 === A2_RTYPE
|
2012-02-08 15:47:26 +01:00
|
|
|
val id_op2 = Mux(io.ctrl.sel_alu2 === A2_RTYPE, id_rs2, id_imm)
|
|
|
|
|
2012-10-10 06:35:03 +02:00
|
|
|
io.ctrl.inst := id_inst
|
|
|
|
io.fpu.inst := id_inst
|
2011-10-26 08:02:47 +02:00
|
|
|
|
|
|
|
// execute stage
|
2012-11-05 01:40:14 +01:00
|
|
|
ex_reg_kill := io.ctrl.killd
|
|
|
|
when (!io.ctrl.killd) {
|
|
|
|
ex_reg_pc := id_pc
|
|
|
|
ex_reg_inst := id_inst
|
|
|
|
ex_reg_raddr1 := id_raddr1
|
|
|
|
ex_reg_raddr2 := id_raddr2
|
|
|
|
ex_reg_op2 := id_op2
|
|
|
|
ex_reg_waddr := Mux(io.ctrl.sel_wa === WA_RD, id_inst(31,27).toUFix, RA)
|
|
|
|
ex_reg_ctrl_fn_dw := io.ctrl.fn_dw.toUFix
|
|
|
|
ex_reg_ctrl_fn_alu := io.ctrl.fn_alu
|
|
|
|
ex_reg_ctrl_sel_wb := io.ctrl.sel_wb
|
|
|
|
when (io.ctrl.ren1) { ex_reg_rs1 := id_rs1 }
|
|
|
|
when (io.ctrl.ren2) { ex_reg_rs2 := id_rs2 }
|
|
|
|
}
|
2011-10-26 08:02:47 +02:00
|
|
|
|
2012-03-17 02:34:40 +01:00
|
|
|
val ex_rs1 = Mux(Reg(id_rs1_dmem_bypass), wb_reg_dmem_wdata, ex_reg_rs1)
|
|
|
|
val ex_rs2 = Mux(Reg(id_rs2_dmem_bypass), wb_reg_dmem_wdata, ex_reg_rs2)
|
|
|
|
val ex_op2 = Mux(Reg(id_op2_dmem_bypass), wb_reg_dmem_wdata, ex_reg_op2)
|
|
|
|
|
2011-10-26 08:02:47 +02:00
|
|
|
alu.io.dw := ex_reg_ctrl_fn_dw;
|
|
|
|
alu.io.fn := ex_reg_ctrl_fn_alu;
|
2012-03-17 02:34:40 +01:00
|
|
|
alu.io.in2 := ex_op2.toUFix
|
|
|
|
alu.io.in1 := ex_rs1.toUFix
|
2012-02-25 04:22:35 +01:00
|
|
|
|
2012-03-17 02:34:40 +01:00
|
|
|
io.fpu.fromint_data := ex_rs1
|
2011-10-26 08:02:47 +02:00
|
|
|
|
|
|
|
// divider
|
2012-10-10 06:35:03 +02:00
|
|
|
val div = new rocketDivider(earlyOut = true)
|
|
|
|
div.io.req.valid := io.ctrl.div_val
|
|
|
|
div.io.req.bits.fn := Cat(ex_reg_ctrl_fn_dw, io.ctrl.div_fn)
|
2012-03-17 02:34:40 +01:00
|
|
|
div.io.req.bits.in0 := ex_rs1
|
2012-11-05 01:40:14 +01:00
|
|
|
div.io.req.bits.in1 := ex_op2
|
2012-02-25 04:22:35 +01:00
|
|
|
div.io.req_tag := ex_reg_waddr
|
2012-10-10 06:35:03 +02:00
|
|
|
div.io.req_kill := io.ctrl.div_kill
|
2012-02-25 04:22:35 +01:00
|
|
|
div.io.resp_rdy := !dmem_resp_replay
|
|
|
|
io.ctrl.div_rdy := div.io.req.ready
|
|
|
|
io.ctrl.div_result_val := div.io.resp_val
|
2011-10-26 08:02:47 +02:00
|
|
|
|
|
|
|
// multiplier
|
2012-10-10 06:35:03 +02:00
|
|
|
var mul_io = new rocketMultiplier(unroll = 4, earlyOut = true).io
|
2012-02-25 04:22:35 +01:00
|
|
|
if (HAVE_VEC)
|
|
|
|
{
|
|
|
|
val vu_mul = new rocketVUMultiplier(nwbq = 1)
|
|
|
|
vu_mul.io.vu.req <> io.vec_imul_req
|
|
|
|
vu_mul.io.vu.resp <> io.vec_imul_resp
|
|
|
|
mul_io = vu_mul.io.cpu
|
|
|
|
}
|
2012-10-10 06:35:03 +02:00
|
|
|
mul_io.req.valid := io.ctrl.mul_val
|
|
|
|
mul_io.req.bits.fn := Cat(ex_reg_ctrl_fn_dw, io.ctrl.mul_fn)
|
2012-03-17 02:34:40 +01:00
|
|
|
mul_io.req.bits.in0 := ex_rs1
|
2012-11-05 01:40:14 +01:00
|
|
|
mul_io.req.bits.in1 := ex_op2
|
2012-02-25 04:22:35 +01:00
|
|
|
mul_io.req_tag := ex_reg_waddr
|
2012-10-10 06:35:03 +02:00
|
|
|
mul_io.req_kill := io.ctrl.mul_kill
|
2012-02-25 04:22:35 +01:00
|
|
|
mul_io.resp_rdy := !dmem_resp_replay && !div.io.resp_val
|
|
|
|
io.ctrl.mul_rdy := mul_io.req.ready
|
|
|
|
io.ctrl.mul_result_val := mul_io.resp_val
|
2011-11-02 01:59:27 +01:00
|
|
|
|
2011-11-18 08:50:45 +01:00
|
|
|
io.ctrl.ex_waddr := ex_reg_waddr; // for load/use hazard detection & bypass control
|
2011-10-26 08:02:47 +02:00
|
|
|
|
2011-11-02 01:59:27 +01:00
|
|
|
// D$ request interface (registered inside D$ module)
|
|
|
|
// other signals (req_val, req_rdy) connect to control module
|
2012-05-02 03:23:04 +02:00
|
|
|
io.dmem.req.bits.idx := ex_effective_address
|
|
|
|
io.dmem.req.bits.data := Mux(io.ctrl.mem_fp_val, io.fpu.store_data, mem_reg_rs2)
|
|
|
|
io.dmem.req.bits.tag := Cat(ex_reg_waddr, io.ctrl.ex_fp_val)
|
2012-02-27 03:26:29 +01:00
|
|
|
io.dtlb.vpn := ex_effective_address >> UFix(PGIDX_BITS)
|
2011-10-26 08:02:47 +02:00
|
|
|
|
2011-11-02 01:59:27 +01:00
|
|
|
// processor control regfile read
|
2012-03-24 21:03:31 +01:00
|
|
|
pcr.io.r.en := io.ctrl.pcr != PCR_N
|
|
|
|
pcr.io.r.addr := wb_reg_raddr1
|
2011-11-10 09:50:09 +01:00
|
|
|
|
2012-02-20 08:15:45 +01:00
|
|
|
pcr.io.host <> io.host
|
2011-11-14 12:24:02 +01:00
|
|
|
|
|
|
|
io.ctrl.irq_timer := pcr.io.irq_timer;
|
|
|
|
io.ctrl.irq_ipi := pcr.io.irq_ipi;
|
2011-11-09 23:52:17 +01:00
|
|
|
io.ctrl.status := pcr.io.status;
|
2012-07-18 07:52:53 +02:00
|
|
|
io.ctrl.pcr_replay := pcr.io.replay
|
2011-11-09 23:52:17 +01:00
|
|
|
io.ptbr := pcr.io.ptbr;
|
2011-11-14 13:13:13 +01:00
|
|
|
io.ptbr_wen := pcr.io.ptbr_wen;
|
2011-11-02 01:59:27 +01:00
|
|
|
|
2011-10-26 08:02:47 +02:00
|
|
|
// branch resolution logic
|
2012-10-12 01:50:15 +02:00
|
|
|
io.ctrl.jalr_eq := ex_reg_rs1 === id_pc.toFix && ex_reg_op2(id_imm_small.getWidth-1,0) === UFix(0)
|
2012-03-17 02:34:40 +01:00
|
|
|
io.ctrl.br_eq := (ex_rs1 === ex_rs2)
|
|
|
|
io.ctrl.br_ltu := (ex_rs1.toUFix < ex_rs2.toUFix)
|
2011-11-02 01:59:27 +01:00
|
|
|
io.ctrl.br_lt :=
|
2012-03-17 02:34:40 +01:00
|
|
|
(~(ex_rs1(63) ^ ex_rs2(63)) & io.ctrl.br_ltu |
|
|
|
|
ex_rs1(63) & ~ex_rs2(63)).toBool
|
2011-10-26 08:02:47 +02:00
|
|
|
|
2011-11-16 11:04:28 +01:00
|
|
|
// time stamp counter
|
|
|
|
val tsc_reg = Reg(resetVal = UFix(0,64));
|
2012-02-12 02:20:33 +01:00
|
|
|
tsc_reg := tsc_reg + UFix(1);
|
2012-01-02 06:28:38 +01:00
|
|
|
// instructions retired counter
|
|
|
|
val irt_reg = Reg(resetVal = UFix(0,64));
|
2012-02-23 23:43:49 +01:00
|
|
|
when (io.ctrl.wb_valid) { irt_reg := irt_reg + UFix(1); }
|
2011-11-16 11:04:28 +01:00
|
|
|
|
2011-10-26 08:02:47 +02:00
|
|
|
// writeback select mux
|
|
|
|
ex_wdata :=
|
2012-10-12 01:50:15 +02:00
|
|
|
Mux(ex_reg_ctrl_sel_wb === WB_PC, ex_pc_plus4.toFix,
|
2011-11-16 11:04:28 +01:00
|
|
|
Mux(ex_reg_ctrl_sel_wb === WB_TSC, tsc_reg,
|
2012-01-02 06:28:38 +01:00
|
|
|
Mux(ex_reg_ctrl_sel_wb === WB_IRT, irt_reg,
|
2012-03-24 21:03:31 +01:00
|
|
|
ex_alu_out))).toBits // WB_ALU
|
2012-02-12 10:35:55 +01:00
|
|
|
|
|
|
|
// subword store data generation
|
|
|
|
val storegen = new StoreDataGen
|
|
|
|
storegen.io.typ := io.ctrl.ex_mem_type
|
2012-03-17 02:34:40 +01:00
|
|
|
storegen.io.din := ex_rs2
|
2011-10-26 08:02:47 +02:00
|
|
|
|
2011-11-02 01:59:27 +01:00
|
|
|
// memory stage
|
2012-11-05 01:40:14 +01:00
|
|
|
mem_reg_kill := ex_reg_kill
|
|
|
|
when (!ex_reg_kill) {
|
|
|
|
mem_reg_pc := ex_reg_pc
|
|
|
|
mem_reg_inst := ex_reg_inst
|
|
|
|
mem_reg_rs2 := storegen.io.dout
|
|
|
|
mem_reg_waddr := ex_reg_waddr
|
|
|
|
mem_reg_wdata := ex_wdata
|
|
|
|
mem_reg_raddr1 := ex_reg_raddr1
|
|
|
|
mem_reg_raddr2 := ex_reg_raddr2
|
|
|
|
}
|
2011-11-02 01:59:27 +01:00
|
|
|
|
2011-11-02 05:25:52 +01:00
|
|
|
// for load/use hazard detection (load byte/halfword)
|
|
|
|
io.ctrl.mem_waddr := mem_reg_waddr;
|
|
|
|
|
2011-11-02 21:32:32 +01:00
|
|
|
// 32/64 bit load handling (moved to earlier in file)
|
2011-11-02 05:25:52 +01:00
|
|
|
|
2012-02-12 13:36:01 +01:00
|
|
|
// writeback arbitration
|
2012-05-02 03:23:04 +02:00
|
|
|
val dmem_resp_xpu = !io.dmem.resp.bits.tag(0).toBool
|
|
|
|
val dmem_resp_fpu = io.dmem.resp.bits.tag(0).toBool
|
|
|
|
val dmem_resp_waddr = io.dmem.resp.bits.tag.toUFix >> UFix(1)
|
|
|
|
dmem_resp_replay := io.dmem.resp.bits.replay && dmem_resp_xpu;
|
2012-02-12 02:20:33 +01:00
|
|
|
r_dmem_resp_replay := dmem_resp_replay
|
|
|
|
r_dmem_resp_waddr := dmem_resp_waddr
|
2012-05-02 03:23:04 +02:00
|
|
|
r_dmem_fp_replay := io.dmem.resp.bits.replay && dmem_resp_fpu;
|
2012-02-08 13:21:05 +01:00
|
|
|
|
|
|
|
val mem_ll_waddr = Mux(dmem_resp_replay, dmem_resp_waddr,
|
2012-02-25 04:22:35 +01:00
|
|
|
Mux(div.io.resp_val, div.io.resp_tag,
|
2012-11-05 01:40:14 +01:00
|
|
|
mul_io.resp_tag))
|
2012-02-25 04:22:35 +01:00
|
|
|
val mem_ll_wdata = Mux(div.io.resp_val, div.io.resp_bits,
|
2012-11-05 01:40:14 +01:00
|
|
|
mul_io.resp_bits)
|
2012-02-25 04:22:35 +01:00
|
|
|
val mem_ll_wb = dmem_resp_replay || div.io.resp_val || mul_io.resp_val
|
2011-11-02 01:59:27 +01:00
|
|
|
|
2012-05-02 03:23:04 +02:00
|
|
|
io.fpu.dmem_resp_val := io.dmem.resp.valid && dmem_resp_fpu
|
|
|
|
io.fpu.dmem_resp_data := io.dmem.resp.bits.data
|
|
|
|
io.fpu.dmem_resp_type := io.dmem.resp.bits.typ
|
2012-02-12 13:36:01 +01:00
|
|
|
io.fpu.dmem_resp_tag := dmem_resp_waddr
|
|
|
|
|
|
|
|
// writeback stage
|
2012-11-05 01:40:14 +01:00
|
|
|
when (io.ctrl.mem_load) {
|
|
|
|
wb_reg_dmem_wdata := io.dmem.resp.bits.data
|
|
|
|
}
|
|
|
|
when (!mem_reg_kill) {
|
|
|
|
wb_reg_pc := mem_reg_pc
|
|
|
|
wb_reg_inst := mem_reg_inst
|
|
|
|
wb_reg_rs2 := mem_reg_rs2
|
|
|
|
wb_reg_vec_waddr := mem_reg_waddr
|
|
|
|
wb_reg_vec_wdata := mem_reg_wdata
|
|
|
|
wb_reg_raddr1 := mem_reg_raddr1
|
|
|
|
wb_reg_raddr2 := mem_reg_raddr2
|
|
|
|
wb_reg_waddr := mem_reg_waddr
|
|
|
|
wb_reg_wdata := Mux(io.ctrl.mem_fp_val && io.ctrl.mem_wen, io.fpu.toint_data, mem_reg_wdata)
|
|
|
|
}
|
|
|
|
wb_reg_ll_wb := mem_ll_wb
|
|
|
|
when (mem_ll_wb) {
|
|
|
|
wb_reg_waddr := mem_ll_waddr
|
|
|
|
wb_reg_wdata := mem_ll_wdata
|
|
|
|
}
|
2011-11-02 01:59:27 +01:00
|
|
|
|
2012-02-15 22:30:22 +01:00
|
|
|
// regfile write
|
2012-02-23 23:43:49 +01:00
|
|
|
val wb_src_dmem = Reg(io.ctrl.mem_load) && io.ctrl.wb_valid || r_dmem_resp_replay
|
2012-02-15 22:30:22 +01:00
|
|
|
|
|
|
|
if (HAVE_VEC)
|
|
|
|
{
|
|
|
|
// vector datapath
|
|
|
|
val vec = new rocketDpathVec()
|
|
|
|
|
|
|
|
vec.io.ctrl <> io.vec_ctrl
|
|
|
|
io.vec_iface <> vec.io.iface
|
|
|
|
|
2012-03-21 23:08:48 +01:00
|
|
|
vec.io.valid := io.ctrl.wb_valid && pcr.io.status(SR_EV)
|
2012-02-15 22:30:22 +01:00
|
|
|
vec.io.inst := wb_reg_inst
|
2012-02-25 21:21:10 +01:00
|
|
|
vec.io.waddr := wb_reg_vec_waddr
|
2012-02-15 22:30:22 +01:00
|
|
|
vec.io.raddr1 := wb_reg_raddr1
|
|
|
|
vec.io.vecbank := pcr.io.vecbank
|
|
|
|
vec.io.vecbankcnt := pcr.io.vecbankcnt
|
2012-02-25 21:21:10 +01:00
|
|
|
vec.io.wdata := wb_reg_vec_wdata
|
2012-02-15 22:30:22 +01:00
|
|
|
vec.io.rs2 := wb_reg_rs2
|
|
|
|
|
2012-03-14 22:15:28 +01:00
|
|
|
pcr.io.vec_irq_aux := vec.io.irq_aux
|
2012-03-14 06:21:26 +01:00
|
|
|
pcr.io.vec_appvl := vec.io.appvl
|
|
|
|
pcr.io.vec_nxregs := vec.io.nxregs
|
|
|
|
pcr.io.vec_nfregs := vec.io.nfregs
|
|
|
|
|
2012-02-15 22:30:22 +01:00
|
|
|
wb_wdata :=
|
|
|
|
Mux(vec.io.wen, Cat(Bits(0,52), vec.io.appvl),
|
2012-05-02 03:23:04 +02:00
|
|
|
Mux(wb_src_dmem, io.dmem.resp.bits.data_subword,
|
2012-02-25 21:21:10 +01:00
|
|
|
wb_reg_wdata))
|
2012-02-15 22:30:22 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-03-14 22:15:28 +01:00
|
|
|
pcr.io.vec_irq_aux := UFix(0)
|
2012-03-14 06:21:26 +01:00
|
|
|
pcr.io.vec_appvl := UFix(0)
|
|
|
|
pcr.io.vec_nxregs := UFix(0)
|
|
|
|
pcr.io.vec_nfregs := UFix(0)
|
|
|
|
|
2012-02-15 22:30:22 +01:00
|
|
|
wb_wdata :=
|
2012-05-02 03:23:04 +02:00
|
|
|
Mux(wb_src_dmem, io.dmem.resp.bits.data_subword,
|
2012-02-25 21:21:10 +01:00
|
|
|
wb_reg_wdata)
|
2012-02-15 22:30:22 +01:00
|
|
|
}
|
2012-02-09 11:35:09 +01:00
|
|
|
|
2012-11-05 01:40:14 +01:00
|
|
|
val rf_wen = io.ctrl.wb_wen || wb_reg_ll_wb
|
|
|
|
val rf_waddr = wb_reg_waddr
|
|
|
|
val rf_wdata = Mux(io.ctrl.wb_wen && io.ctrl.pcr != PCR_N, pcr.io.r.data, wb_wdata)
|
|
|
|
List(rf_wen, rf_waddr, rf_wdata).map(debug _)
|
|
|
|
when (rf_wen) { writeRF(rf_waddr, rf_wdata) }
|
2012-02-09 07:30:45 +01:00
|
|
|
|
2012-02-25 21:21:10 +01:00
|
|
|
io.ctrl.wb_waddr := wb_reg_waddr
|
2012-02-08 13:21:05 +01:00
|
|
|
io.ctrl.mem_wb := dmem_resp_replay;
|
2012-02-09 10:28:16 +01:00
|
|
|
|
2011-11-02 01:59:27 +01:00
|
|
|
// scoreboard clear (for div/mul and D$ load miss writebacks)
|
2012-02-08 13:21:05 +01:00
|
|
|
io.ctrl.sboard_clr := mem_ll_wb
|
|
|
|
io.ctrl.sboard_clra := mem_ll_waddr
|
|
|
|
io.ctrl.fp_sboard_clr := r_dmem_fp_replay
|
|
|
|
io.ctrl.fp_sboard_clra := r_dmem_resp_waddr
|
2012-04-01 23:52:33 +02:00
|
|
|
io.ctrl.fp_sboard_wb_waddr := Reg(mem_reg_waddr)
|
2012-04-01 07:23:51 +02:00
|
|
|
|
2011-11-02 01:59:27 +01:00
|
|
|
// processor control regfile write
|
2012-03-24 21:03:31 +01:00
|
|
|
pcr.io.w.addr := wb_reg_raddr1
|
|
|
|
pcr.io.w.en := io.ctrl.pcr === PCR_T || io.ctrl.pcr === PCR_S || io.ctrl.pcr === PCR_C
|
|
|
|
pcr.io.w.data := Mux(io.ctrl.pcr === PCR_S, pcr.io.r.data | wb_reg_wdata,
|
|
|
|
Mux(io.ctrl.pcr === PCR_C, pcr.io.r.data & ~wb_reg_wdata,
|
|
|
|
wb_reg_wdata))
|
2011-10-26 08:02:47 +02:00
|
|
|
|
2012-01-03 00:42:39 +01:00
|
|
|
pcr.io.eret := io.ctrl.wb_eret;
|
2011-11-18 08:50:45 +01:00
|
|
|
pcr.io.exception := io.ctrl.exception;
|
|
|
|
pcr.io.cause := io.ctrl.cause;
|
2012-01-03 00:42:39 +01:00
|
|
|
pcr.io.pc := wb_reg_pc;
|
2011-11-18 08:50:45 +01:00
|
|
|
pcr.io.badvaddr_wen := io.ctrl.badvaddr_wen;
|
2012-03-14 22:15:28 +01:00
|
|
|
pcr.io.vec_irq_aux_wen := io.ctrl.vec_irq_aux_wen
|
2011-10-26 08:02:47 +02:00
|
|
|
}
|