2011-10-26 08:02:47 +02:00
|
|
|
package Top {
|
|
|
|
|
|
|
|
import Chisel._
|
|
|
|
import Node._;
|
2012-02-09 06:43:45 +01:00
|
|
|
|
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
|
|
|
|
2011-11-10 09:23:29 +01:00
|
|
|
class ioDpathDmem extends Bundle()
|
|
|
|
{
|
2012-01-24 09:15:17 +01:00
|
|
|
val req_addr = UFix(VADDR_BITS+1, OUTPUT);
|
2012-01-18 19:28:48 +01:00
|
|
|
val req_tag = UFix(CPU_TAG_BITS, OUTPUT);
|
|
|
|
val req_data = Bits(64, OUTPUT);
|
|
|
|
val resp_val = Bool(INPUT);
|
|
|
|
val resp_miss = Bool(INPUT);
|
|
|
|
val resp_replay = Bool(INPUT);
|
2012-02-13 08:31:50 +01:00
|
|
|
val resp_type = Bits(3, INPUT);
|
2012-01-18 19:28:48 +01:00
|
|
|
val resp_tag = Bits(CPU_TAG_BITS, INPUT);
|
|
|
|
val resp_data = Bits(64, INPUT);
|
|
|
|
val resp_data_subword = Bits(64, INPUT);
|
2011-11-10 09:23:29 +01:00
|
|
|
}
|
|
|
|
|
2011-11-10 06:54:11 +01:00
|
|
|
class ioDpathImem extends Bundle()
|
|
|
|
{
|
2012-01-24 09:15:17 +01:00
|
|
|
val req_addr = UFix(VADDR_BITS+1, OUTPUT);
|
2012-01-18 19:28:48 +01:00
|
|
|
val resp_data = Bits(32, INPUT);
|
2011-11-10 06:54:11 +01:00
|
|
|
}
|
|
|
|
|
2011-10-26 08:02:47 +02:00
|
|
|
class ioDpathAll extends Bundle()
|
|
|
|
{
|
2012-02-20 08:15:45 +01:00
|
|
|
val host = new ioHTIF();
|
2011-11-02 01:59:27 +01:00
|
|
|
val ctrl = new ioCtrlDpath().flip();
|
2011-10-26 08:02:47 +02:00
|
|
|
val debug = new ioDebug();
|
2011-11-10 09:23:29 +01:00
|
|
|
val dmem = new ioDpathDmem();
|
2012-02-22 02:42:00 +01:00
|
|
|
val ext_mem = new ioDmem(List("req_val", "req_idx", "req_ppn", "req_data", "req_tag", "resp_val", "resp_data", "resp_type", "resp_tag"))
|
2011-11-10 06:54:11 +01:00
|
|
|
val imem = new ioDpathImem();
|
2012-01-18 19:28:48 +01:00
|
|
|
val ptbr_wen = Bool(OUTPUT);
|
|
|
|
val ptbr = UFix(PADDR_BITS, OUTPUT);
|
2012-02-08 08:54:25 +01:00
|
|
|
val fpu = new ioDpathFPU();
|
2012-02-15 22:30:22 +01:00
|
|
|
val vec_ctrl = new ioCtrlDpathVec().flip()
|
|
|
|
val vec_iface = new ioDpathVecInterface()
|
2011-10-26 08:02:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
class rocketDpath extends Component
|
|
|
|
{
|
|
|
|
val io = new ioDpathAll();
|
|
|
|
|
2012-02-09 10:32:52 +01:00
|
|
|
val btb = new rocketDpathBTB(4); // # of entries in BTB
|
2011-11-10 20:26:13 +01:00
|
|
|
|
2011-10-26 08:02:47 +02:00
|
|
|
val if_btb_target = btb.io.target;
|
|
|
|
|
|
|
|
val pcr = new rocketDpathPCR();
|
|
|
|
val ex_pcr = pcr.io.r.data;
|
|
|
|
|
|
|
|
val alu = new rocketDpathALU();
|
|
|
|
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
|
|
|
|
|
|
|
val div = new rocketDivider(64);
|
2012-02-09 12:47:59 +01:00
|
|
|
val div_result = div.io.result;
|
|
|
|
val div_result_tag = div.io.result_tag;
|
|
|
|
val div_result_val = div.io.result_val;
|
2011-10-26 08:02:47 +02:00
|
|
|
|
|
|
|
val mul = new rocketMultiplier();
|
|
|
|
val mul_result = mul.io.result;
|
|
|
|
val mul_result_tag = mul.io.result_tag;
|
|
|
|
val mul_result_val = mul.io.result_val;
|
|
|
|
|
2011-12-01 06:54:55 +01:00
|
|
|
val rfile = new rocketDpathRegfile();
|
2011-10-26 08:02:47 +02:00
|
|
|
|
|
|
|
// instruction fetch definitions
|
2012-01-24 09:15:17 +01:00
|
|
|
val if_reg_pc = Reg(resetVal = UFix(START_ADDR,VADDR_BITS+1));
|
2011-10-26 08:02:47 +02:00
|
|
|
|
|
|
|
// instruction decode definitions
|
2011-11-02 01:59:27 +01:00
|
|
|
val id_reg_inst = Reg(resetVal = NOP);
|
2012-01-24 09:15:17 +01:00
|
|
|
val id_reg_pc = Reg() { UFix(width = VADDR_BITS+1) };
|
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() };
|
2011-11-18 08:50:45 +01:00
|
|
|
val ex_reg_ctrl_eret = Reg(resetVal = Bool(false));
|
2012-01-02 01:09:40 +01:00
|
|
|
val ex_reg_ctrl_fn_dw = Reg() { UFix() };
|
|
|
|
val ex_reg_ctrl_fn_alu = Reg() { UFix() };
|
2011-11-02 01:59:27 +01:00
|
|
|
val ex_reg_ctrl_mul_val = Reg(resetVal = Bool(false));
|
2012-01-02 01:09:40 +01:00
|
|
|
val ex_reg_ctrl_mul_fn = Reg() { UFix() };
|
2011-11-02 01:59:27 +01:00
|
|
|
val ex_reg_ctrl_div_val = Reg(resetVal = Bool(false));
|
2012-01-02 01:09:40 +01:00
|
|
|
val ex_reg_ctrl_div_fn = Reg() { UFix() };
|
|
|
|
val ex_reg_ctrl_sel_wb = Reg() { UFix() };
|
2011-11-02 01:59:27 +01:00
|
|
|
val ex_reg_ctrl_ren_pcr = Reg(resetVal = Bool(false));
|
2012-02-15 08:34:57 +01:00
|
|
|
val ex_reg_ext_mem_tag = Reg() { Bits() };
|
2011-11-02 01:59:27 +01:00
|
|
|
val ex_wdata = Wire() { Bits() };
|
|
|
|
|
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-02-07 02:26:45 +01:00
|
|
|
val mem_wdata = Wire() { Bits() };
|
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-01-02 01:09:40 +01:00
|
|
|
val wb_reg_waddr = Reg() { UFix() };
|
|
|
|
val wb_reg_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-02-02 00:36:01 +01:00
|
|
|
val wb_wdata = Wire() { Bits() };
|
2011-11-02 01:59:27 +01:00
|
|
|
|
2012-02-08 13:21:05 +01:00
|
|
|
val dmem_resp_replay = Wire() { 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-11-02 03:05:27 +01:00
|
|
|
|
2011-10-26 08:02:47 +02:00
|
|
|
// instruction fetch stage
|
2011-11-09 23:52:17 +01:00
|
|
|
val if_pc_plus4 = if_reg_pc + UFix(4);
|
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
|
|
|
|
|
|
|
val if_next_pc =
|
2012-01-24 09:15:17 +01:00
|
|
|
Mux(io.ctrl.sel_pc === PC_BTB, Cat(if_btb_target(VADDR_BITS-1), if_btb_target),
|
2012-02-02 22:33:27 +01:00
|
|
|
Mux(io.ctrl.sel_pc === PC_EX4, ex_pc_plus4,
|
2012-02-09 10:32:52 +01:00
|
|
|
Mux(io.ctrl.sel_pc === PC_BR, ex_branch_target,
|
|
|
|
Mux(io.ctrl.sel_pc === PC_JR, ex_effective_address,
|
2012-01-24 09:15:17 +01:00
|
|
|
Mux(io.ctrl.sel_pc === PC_PCR, wb_reg_wdata(VADDR_BITS,0), // only used for ERET
|
|
|
|
Mux(io.ctrl.sel_pc === PC_EVEC, Cat(pcr.io.evec(VADDR_BITS-1), pcr.io.evec),
|
2012-01-18 06:12:31 +01:00
|
|
|
Mux(io.ctrl.sel_pc === PC_WB, wb_reg_pc,
|
2012-02-09 10:32:52 +01:00
|
|
|
if_pc_plus4))))))); // PC_4
|
2011-11-10 12:38:59 +01:00
|
|
|
|
2012-01-12 02:49:32 +01:00
|
|
|
when (!io.ctrl.stallf) {
|
2012-02-12 02:20:33 +01:00
|
|
|
if_reg_pc := if_next_pc.toUFix;
|
2011-10-26 08:02:47 +02:00
|
|
|
}
|
2011-11-18 08:50:45 +01:00
|
|
|
|
2012-01-24 09:15:17 +01:00
|
|
|
io.ctrl.xcpt_ma_inst := if_next_pc(1,0) != Bits(0)
|
2011-11-10 12:38:59 +01:00
|
|
|
|
2011-10-26 08:02:47 +02:00
|
|
|
io.imem.req_addr :=
|
|
|
|
Mux(io.ctrl.stallf, if_reg_pc,
|
2011-11-18 08:50:45 +01:00
|
|
|
if_next_pc.toUFix);
|
2011-10-26 08:02:47 +02:00
|
|
|
|
2012-02-09 00:03:59 +01:00
|
|
|
btb.io.current_pc := if_reg_pc;
|
2012-01-23 18:51:35 +01:00
|
|
|
btb.io.hit <> io.ctrl.btb_hit;
|
|
|
|
btb.io.wen <> io.ctrl.wen_btb;
|
|
|
|
btb.io.clr <> io.ctrl.clr_btb;
|
2012-02-09 00:03:59 +01:00
|
|
|
btb.io.correct_pc := ex_reg_pc;
|
2012-02-09 10:32:52 +01:00
|
|
|
btb.io.correct_target := ex_branch_target
|
|
|
|
btb.io.invalidate := io.ctrl.flush_inst
|
2011-10-26 08:02:47 +02:00
|
|
|
|
|
|
|
// instruction decode stage
|
|
|
|
when (!io.ctrl.stalld) {
|
2012-02-12 02:20:33 +01:00
|
|
|
id_reg_pc := if_reg_pc;
|
2012-02-23 23:43:49 +01:00
|
|
|
id_reg_inst := Mux(io.ctrl.killf, NOP, io.imem.resp_data)
|
2011-10-26 08:02:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
val id_raddr1 = id_reg_inst(26,22).toUFix;
|
|
|
|
val id_raddr2 = id_reg_inst(21,17).toUFix;
|
|
|
|
|
|
|
|
// regfile read
|
2012-01-23 18:51:35 +01:00
|
|
|
rfile.io.r0.en <> io.ctrl.ren2;
|
2011-10-26 08:02:47 +02:00
|
|
|
rfile.io.r0.addr := id_raddr2;
|
|
|
|
val id_rdata2 = rfile.io.r0.data;
|
|
|
|
|
2012-01-23 18:51:35 +01:00
|
|
|
rfile.io.r1.en <> io.ctrl.ren1;
|
2011-10-26 08:02:47 +02:00
|
|
|
rfile.io.r1.addr := id_raddr1;
|
|
|
|
val id_rdata1 = rfile.io.r1.data;
|
|
|
|
|
2011-11-02 01:59:27 +01:00
|
|
|
// destination register selection
|
2011-10-26 08:02:47 +02:00
|
|
|
val id_waddr =
|
|
|
|
Mux(io.ctrl.sel_wa === WA_RD, id_reg_inst(31,27).toUFix,
|
2012-02-08 13:21:05 +01:00
|
|
|
RA); // WA_RA
|
2011-10-26 08:02:47 +02:00
|
|
|
|
2011-11-02 01:59:27 +01:00
|
|
|
// bypass muxes
|
2011-10-26 08:02:47 +02:00
|
|
|
val id_rs1 =
|
2012-02-09 07:30:45 +01:00
|
|
|
Mux(io.ext_mem.req_val, Cat(io.ext_mem.req_ppn, io.ext_mem.req_idx),
|
2012-02-08 13:21:05 +01:00
|
|
|
Mux(io.ctrl.ex_wen && id_raddr1 === ex_reg_waddr, ex_wdata,
|
|
|
|
Mux(io.ctrl.mem_wen && id_raddr1 === mem_reg_waddr, mem_wdata,
|
|
|
|
Mux((io.ctrl.wb_wen || wb_reg_ll_wb) && id_raddr1 === wb_reg_waddr, wb_wdata,
|
2012-02-09 07:30:45 +01:00
|
|
|
id_rdata1))))
|
2011-10-26 08:02:47 +02:00
|
|
|
|
|
|
|
val id_rs2 =
|
2012-02-09 07:30:45 +01:00
|
|
|
Mux(io.ext_mem.req_val, io.ext_mem.req_data,
|
2012-02-08 13:21:05 +01:00
|
|
|
Mux(io.ctrl.ex_wen && id_raddr2 === ex_reg_waddr, ex_wdata,
|
|
|
|
Mux(io.ctrl.mem_wen && id_raddr2 === mem_reg_waddr, mem_wdata,
|
|
|
|
Mux((io.ctrl.wb_wen || wb_reg_ll_wb) && id_raddr2 === wb_reg_waddr, wb_wdata,
|
2012-02-09 07:30:45 +01:00
|
|
|
id_rdata2))))
|
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
|
|
|
|
val id_imm_sign = Mux(id_imm_bj, id_reg_inst(31),
|
|
|
|
Mux(id_imm_l, id_reg_inst(26),
|
|
|
|
Mux(id_imm_zero, Bits(0,1),
|
|
|
|
id_reg_inst(21)))) // IMM_ITYPE
|
|
|
|
val id_imm_small = Mux(id_imm_zero, Bits(0,12),
|
|
|
|
Cat(Mux(id_imm_bj, id_reg_inst(31,27), id_reg_inst(21,17)), id_reg_inst(16,10)))
|
|
|
|
val id_imm = Cat(Fill(32, id_imm_sign),
|
|
|
|
Mux(id_imm_l, Cat(id_reg_inst(26,7), Bits(0,12)),
|
|
|
|
Mux(id_imm_ibz, Cat(Fill(20, id_imm_sign), id_imm_small),
|
|
|
|
Cat(Fill(7, id_imm_sign), id_reg_inst(31,7))))) // A2_JTYPE
|
|
|
|
|
|
|
|
val id_op2 = Mux(io.ctrl.sel_alu2 === A2_RTYPE, id_rs2, id_imm)
|
|
|
|
|
2012-02-12 13:36:01 +01:00
|
|
|
io.ctrl.inst := id_reg_inst
|
|
|
|
io.fpu.inst := id_reg_inst
|
2011-10-26 08:02:47 +02:00
|
|
|
|
|
|
|
// execute stage
|
2012-02-12 02:20:33 +01:00
|
|
|
ex_reg_pc := id_reg_pc;
|
|
|
|
ex_reg_inst := id_reg_inst
|
|
|
|
ex_reg_raddr1 := id_raddr1
|
|
|
|
ex_reg_raddr2 := id_raddr2;
|
|
|
|
ex_reg_op2 := id_op2;
|
|
|
|
ex_reg_rs2 := id_rs2;
|
|
|
|
ex_reg_rs1 := id_rs1;
|
|
|
|
ex_reg_waddr := id_waddr;
|
|
|
|
ex_reg_ctrl_fn_dw := io.ctrl.fn_dw.toUFix;
|
|
|
|
ex_reg_ctrl_fn_alu := io.ctrl.fn_alu;
|
|
|
|
ex_reg_ctrl_mul_fn := io.ctrl.mul_fn;
|
|
|
|
ex_reg_ctrl_div_fn := io.ctrl.div_fn;
|
|
|
|
ex_reg_ctrl_sel_wb := io.ctrl.sel_wb;
|
|
|
|
ex_reg_ctrl_ren_pcr := io.ctrl.ren_pcr;
|
2012-02-15 08:34:57 +01:00
|
|
|
ex_reg_ext_mem_tag := io.ext_mem.req_tag
|
2011-10-26 08:02:47 +02:00
|
|
|
|
|
|
|
when(io.ctrl.killd) {
|
2012-02-12 02:20:33 +01:00
|
|
|
ex_reg_ctrl_div_val := Bool(false);
|
|
|
|
ex_reg_ctrl_mul_val := Bool(false);
|
|
|
|
ex_reg_ctrl_eret := Bool(false);
|
2011-10-26 08:02:47 +02:00
|
|
|
}
|
2012-02-12 02:20:33 +01:00
|
|
|
.otherwise {
|
|
|
|
ex_reg_ctrl_div_val := io.ctrl.div_val;
|
|
|
|
ex_reg_ctrl_mul_val := io.ctrl.mul_val;
|
|
|
|
ex_reg_ctrl_eret := io.ctrl.id_eret;
|
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-02-08 15:47:26 +01:00
|
|
|
alu.io.in2 := ex_reg_op2.toUFix;
|
|
|
|
alu.io.in1 := ex_reg_rs1.toUFix;
|
2011-10-26 08:02:47 +02:00
|
|
|
|
|
|
|
// divider
|
2011-12-20 01:57:53 +01:00
|
|
|
div.io.dw := ex_reg_ctrl_fn_dw;
|
2011-10-26 08:02:47 +02:00
|
|
|
div.io.div_fn := ex_reg_ctrl_div_fn;
|
2012-01-03 00:42:39 +01:00
|
|
|
div.io.div_val := ex_reg_ctrl_div_val;
|
2012-02-09 11:26:03 +01:00
|
|
|
div.io.div_kill := io.ctrl.killm;
|
2012-02-09 12:47:59 +01:00
|
|
|
div.io.div_tag := ex_reg_waddr;
|
|
|
|
div.io.in0 := ex_reg_rs1;
|
|
|
|
div.io.in1 := ex_reg_rs2;
|
|
|
|
div.io.result_rdy:= !dmem_resp_replay
|
2011-10-26 08:02:47 +02:00
|
|
|
|
2011-11-02 01:59:27 +01:00
|
|
|
io.ctrl.div_rdy := div.io.div_rdy;
|
2012-02-09 12:47:59 +01:00
|
|
|
io.ctrl.div_result_val := div.io.result_val;
|
2011-10-26 08:02:47 +02:00
|
|
|
|
|
|
|
// multiplier
|
2012-01-03 00:42:39 +01:00
|
|
|
mul.io.mul_val := ex_reg_ctrl_mul_val;
|
2012-02-09 11:26:03 +01:00
|
|
|
mul.io.mul_kill:= io.ctrl.killm;
|
2011-12-17 16:20:00 +01:00
|
|
|
mul.io.dw := ex_reg_ctrl_fn_dw;
|
2011-10-26 08:02:47 +02:00
|
|
|
mul.io.mul_fn := ex_reg_ctrl_mul_fn;
|
|
|
|
mul.io.mul_tag := ex_reg_waddr;
|
|
|
|
mul.io.in0 := ex_reg_rs1;
|
|
|
|
mul.io.in1 := ex_reg_rs2;
|
2012-02-13 05:12:53 +01:00
|
|
|
|
|
|
|
io.fpu.fromint_data := ex_reg_rs1
|
2011-12-17 16:30:47 +01:00
|
|
|
|
|
|
|
io.ctrl.mul_rdy := mul.io.mul_rdy
|
2011-11-02 01:59:27 +01:00
|
|
|
io.ctrl.mul_result_val := mul.io.result_val;
|
2012-02-09 12:47:59 +01:00
|
|
|
mul.io.result_rdy := !dmem_resp_replay && !div.io.result_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-02-08 15:47:26 +01:00
|
|
|
io.dmem.req_addr := ex_effective_address.toUFix;
|
2012-02-13 05:12:53 +01:00
|
|
|
io.dmem.req_data := Mux(io.ctrl.mem_fp_val, io.fpu.store_data, mem_reg_rs2)
|
2012-02-15 08:34:57 +01:00
|
|
|
io.dmem.req_tag := Cat(Mux(io.ctrl.ex_ext_mem_val, ex_reg_ext_mem_tag(CPU_TAG_BITS-2, 0), Cat(ex_reg_waddr, io.ctrl.ex_fp_val)), io.ctrl.ex_ext_mem_val).toUFix
|
2011-10-26 08:02:47 +02:00
|
|
|
|
2011-11-02 01:59:27 +01:00
|
|
|
// processor control regfile read
|
2011-11-10 09:50:09 +01:00
|
|
|
pcr.io.r.en := ex_reg_ctrl_ren_pcr | ex_reg_ctrl_eret;
|
2011-10-26 08:02:47 +02:00
|
|
|
pcr.io.r.addr :=
|
|
|
|
Mux(ex_reg_ctrl_eret, PCR_EPC,
|
2011-11-10 09:50:09 +01:00
|
|
|
ex_reg_raddr2);
|
|
|
|
|
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;
|
|
|
|
io.ptbr := pcr.io.ptbr;
|
2011-11-14 13:13:13 +01:00
|
|
|
io.ptbr_wen := pcr.io.ptbr_wen;
|
2011-10-26 08:02:47 +02:00
|
|
|
io.debug.error_mode := pcr.io.debug.error_mode;
|
2011-11-02 01:59:27 +01:00
|
|
|
|
2011-10-26 08:02:47 +02:00
|
|
|
// branch resolution logic
|
2011-11-02 01:59:27 +01:00
|
|
|
io.ctrl.br_eq := (ex_reg_rs1 === ex_reg_rs2);
|
|
|
|
io.ctrl.br_ltu := (ex_reg_rs1.toUFix < ex_reg_rs2.toUFix);
|
|
|
|
io.ctrl.br_lt :=
|
|
|
|
(~(ex_reg_rs1(63) ^ ex_reg_rs2(63)) & io.ctrl.br_ltu |
|
2011-10-26 08:02:47 +02:00
|
|
|
ex_reg_rs1(63) & ~ex_reg_rs2(63)).toBool;
|
|
|
|
|
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-02-02 22:33:27 +01:00
|
|
|
Mux(ex_reg_ctrl_sel_wb === WB_PC, Cat(Fill(64-VADDR_BITS, ex_pc_plus4(VADDR_BITS-1)), ex_pc_plus4),
|
2011-10-26 08:02:47 +02:00
|
|
|
Mux(ex_reg_ctrl_sel_wb === WB_PCR, ex_pcr,
|
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-02-09 11:35:09 +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
|
|
|
|
storegen.io.din := ex_reg_rs2
|
2011-10-26 08:02:47 +02:00
|
|
|
|
2011-11-02 01:59:27 +01:00
|
|
|
// memory stage
|
2012-02-12 02:20:33 +01:00
|
|
|
mem_reg_pc := ex_reg_pc;
|
|
|
|
mem_reg_inst := ex_reg_inst
|
2012-02-12 10:35:55 +01:00
|
|
|
mem_reg_rs2 := storegen.io.dout
|
2012-02-12 02:20:33 +01:00
|
|
|
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;
|
|
|
|
|
2012-02-07 02:26:45 +01:00
|
|
|
mem_wdata := Mux(io.ctrl.mem_load, io.dmem.resp_data, mem_reg_wdata)
|
|
|
|
|
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-02-09 07:30:45 +01:00
|
|
|
val dmem_resp_ext = io.dmem.resp_tag(0).toBool
|
|
|
|
val dmem_resp_xpu = !io.dmem.resp_tag(0).toBool && !io.dmem.resp_tag(1).toBool
|
|
|
|
val dmem_resp_fpu = !io.dmem.resp_tag(0).toBool && io.dmem.resp_tag(1).toBool
|
|
|
|
val dmem_resp_waddr = io.dmem.resp_tag.toUFix >> UFix(2)
|
|
|
|
val dmem_resp_ext_tag = io.dmem.resp_tag.toUFix >> UFix(1)
|
|
|
|
dmem_resp_replay := io.dmem.resp_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
|
|
|
|
r_dmem_fp_replay := io.dmem.resp_replay && dmem_resp_fpu;
|
2012-02-08 13:21:05 +01:00
|
|
|
|
|
|
|
val mem_ll_waddr = Mux(dmem_resp_replay, dmem_resp_waddr,
|
|
|
|
Mux(div_result_val, div_result_tag,
|
|
|
|
Mux(mul_result_val, mul_result_tag,
|
|
|
|
mem_reg_waddr)))
|
|
|
|
val mem_ll_wdata = Mux(div_result_val, div_result,
|
|
|
|
Mux(mul_result_val, mul_result,
|
2012-02-13 05:12:53 +01:00
|
|
|
Mux(io.ctrl.mem_fp_val && io.ctrl.mem_wen, io.fpu.toint_data,
|
|
|
|
mem_reg_wdata)))
|
2012-02-09 11:26:03 +01:00
|
|
|
val mem_ll_wb = dmem_resp_replay || div_result_val || mul_result_val
|
2011-11-02 01:59:27 +01:00
|
|
|
|
2012-02-12 13:36:01 +01:00
|
|
|
io.fpu.dmem_resp_val := io.dmem.resp_val && dmem_resp_fpu
|
|
|
|
io.fpu.dmem_resp_data := io.dmem.resp_data
|
2012-02-13 08:31:50 +01:00
|
|
|
io.fpu.dmem_resp_type := io.dmem.resp_type
|
2012-02-12 13:36:01 +01:00
|
|
|
io.fpu.dmem_resp_tag := dmem_resp_waddr
|
|
|
|
|
|
|
|
// writeback stage
|
2012-02-12 02:20:33 +01:00
|
|
|
wb_reg_pc := mem_reg_pc;
|
|
|
|
wb_reg_inst := mem_reg_inst
|
|
|
|
wb_reg_ll_wb := mem_ll_wb
|
|
|
|
wb_reg_rs2 := mem_reg_rs2
|
|
|
|
wb_reg_waddr := mem_ll_waddr
|
|
|
|
wb_reg_wdata := mem_ll_wdata
|
|
|
|
wb_reg_raddr1 := mem_reg_raddr1
|
|
|
|
wb_reg_raddr2 := mem_reg_raddr2;
|
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-02-23 23:43:49 +01:00
|
|
|
vec.io.valid := io.ctrl.wb_valid
|
2012-02-15 22:30:22 +01:00
|
|
|
vec.io.inst := wb_reg_inst
|
|
|
|
vec.io.waddr := wb_reg_waddr
|
|
|
|
vec.io.raddr1 := wb_reg_raddr1
|
|
|
|
vec.io.vecbank := pcr.io.vecbank
|
|
|
|
vec.io.vecbankcnt := pcr.io.vecbankcnt
|
|
|
|
vec.io.wdata := wb_reg_wdata
|
|
|
|
vec.io.rs2 := wb_reg_rs2
|
|
|
|
|
|
|
|
wb_wdata :=
|
|
|
|
Mux(vec.io.wen, Cat(Bits(0,52), vec.io.appvl),
|
|
|
|
Mux(wb_src_dmem, io.dmem.resp_data_subword,
|
|
|
|
wb_reg_wdata))
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
wb_wdata :=
|
|
|
|
Mux(wb_src_dmem, io.dmem.resp_data_subword,
|
|
|
|
wb_reg_wdata)
|
|
|
|
}
|
2012-02-09 11:35:09 +01:00
|
|
|
|
2012-02-08 13:21:05 +01:00
|
|
|
rfile.io.w0.addr := wb_reg_waddr
|
|
|
|
rfile.io.w0.en := io.ctrl.wb_wen || wb_reg_ll_wb
|
2012-02-02 00:36:01 +01:00
|
|
|
rfile.io.w0.data := wb_wdata
|
2012-02-09 07:30:45 +01:00
|
|
|
|
|
|
|
io.ext_mem.resp_val := Reg(io.dmem.resp_val && dmem_resp_ext, resetVal = Bool(false))
|
|
|
|
io.ext_mem.resp_tag := Reg(dmem_resp_ext_tag)
|
2012-02-22 02:42:00 +01:00
|
|
|
io.ext_mem.resp_type := Reg(io.dmem.resp_type)
|
2012-02-09 07:30:45 +01:00
|
|
|
io.ext_mem.resp_data := io.dmem.resp_data_subword
|
2011-10-26 08:02:47 +02:00
|
|
|
|
2011-11-02 07:14:34 +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
|
2011-11-02 01:59:27 +01:00
|
|
|
|
|
|
|
// processor control regfile write
|
2012-01-03 00:42:39 +01:00
|
|
|
pcr.io.w.addr := wb_reg_raddr2;
|
2012-02-23 23:43:49 +01:00
|
|
|
pcr.io.w.en := io.ctrl.wen_pcr
|
2012-01-03 00:42:39 +01:00
|
|
|
pcr.io.w.data := wb_reg_wdata;
|
2011-10-26 08:02:47 +02:00
|
|
|
|
2011-11-14 22:48:49 +01:00
|
|
|
pcr.io.di := io.ctrl.irq_disable;
|
|
|
|
pcr.io.ei := io.ctrl.irq_enable;
|
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;
|
2011-10-26 08:02:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|