修改commit的wdata信号量

This commit is contained in:
Liphen 2023-11-22 16:34:26 +08:00
parent 640f13a7c6
commit 392026c13f
6 changed files with 51 additions and 37 deletions

View File

@ -18,7 +18,7 @@ class SrcInfo extends Bundle {
} }
class RdInfo extends Bundle { class RdInfo extends Bundle {
val wdata = UInt(XLEN.W) val wdata = Vec(FuType.num, UInt(XLEN.W))
} }
class InstInfo extends Bundle { class InstInfo extends Bundle {

View File

@ -43,14 +43,14 @@ class Decoder extends Module with HasInstrType {
io.out.inst_info.reg2_raddr := Mux(src2Type === SrcType.reg, rt, 0.U) io.out.inst_info.reg2_raddr := Mux(src2Type === SrcType.reg, rt, 0.U)
io.out.inst_info.fusel := fuType io.out.inst_info.fusel := fuType
io.out.inst_info.op := fuOpType io.out.inst_info.op := fuOpType
when(fuType === FuType.bru) { // when(fuType === FuType.bru) {
def isLink(reg: UInt) = (reg === 1.U || reg === 5.U) // def isLink(reg: UInt) = (reg === 1.U || reg === 5.U)
when(isLink(rd) && fuOpType === ALUOpType.jal) { io.out.inst_info.op := ALUOpType.call } // when(isLink(rd) && fuOpType === ALUOpType.jal) { io.out.inst_info.op := ALUOpType.call }
when(fuOpType === ALUOpType.jalr) { // when(fuOpType === ALUOpType.jalr) {
when(isLink(rs)) { io.out.inst_info.op := ALUOpType.ret } // when(isLink(rs)) { io.out.inst_info.op := ALUOpType.ret }
when(isLink(rd)) { io.out.inst_info.op := ALUOpType.call } // when(isLink(rd)) { io.out.inst_info.op := ALUOpType.call }
} // }
} // }
io.out.inst_info.reg_wen := isrfWen(instrType) io.out.inst_info.reg_wen := isrfWen(instrType)
io.out.inst_info.reg_waddr := Mux(isrfWen(instrType), rd, 0.U) io.out.inst_info.reg_waddr := Mux(isrfWen(instrType), rd, 0.U)
io.out.inst_info.imm := LookupTree( io.out.inst_info.imm := LookupTree(

View File

@ -33,6 +33,7 @@ class CsrExecuteUnit(implicit val config: CpuConfig) extends Bundle {
val out = Output(new Bundle { val out = Output(new Bundle {
val rdata = Vec(config.fuNum, UInt(DATA_WID.W)) val rdata = Vec(config.fuNum, UInt(DATA_WID.W))
val trap_ill = Bool() val trap_ill = Bool()
val ex = Vec(config.fuNum, new ExceptionInfo())
}) })
} }
@ -227,8 +228,6 @@ class Csr(implicit val config: CpuConfig) extends Module with HasCSRConst {
// CSR inst decode // CSR inst decode
val ret = Wire(Bool()) val ret = Wire(Bool())
val isEbreak = addr === privEbreak && op === CSROpType.jmp
val isEcall = addr === privEcall && op === CSROpType.jmp
val isMret = addr === privMret && op === CSROpType.jmp val isMret = addr === privMret && op === CSROpType.jmp
val isSret = addr === privSret && op === CSROpType.jmp val isSret = addr === privSret && op === CSROpType.jmp
val isUret = addr === privUret && op === CSROpType.jmp val isUret = addr === privUret && op === CSROpType.jmp

View File

@ -109,20 +109,30 @@ class ExecuteUnit(implicit val config: CpuConfig) extends Module {
io.memoryStage.inst0.pc := io.executeStage.inst0.pc io.memoryStage.inst0.pc := io.executeStage.inst0.pc
io.memoryStage.inst0.inst_info := io.executeStage.inst0.inst_info io.memoryStage.inst0.inst_info := io.executeStage.inst0.inst_info
io.memoryStage.inst0.rd_info.wdata := fu.inst(0).result io.memoryStage.inst0.rd_info.wdata(FuType.alu) := fu.inst(0).result.alu
io.memoryStage.inst0.ex := Mux( io.memoryStage.inst0.rd_info.wdata(FuType.mdu) := fu.inst(0).result.mdu
io.executeStage.inst0.inst_info.fusel === FuType.lsu, io.memoryStage.inst0.rd_info.wdata(FuType.csr) := io.csr.out.rdata
accessMemCtrl.inst(0).ex.out, io.memoryStage.inst0.rd_info.wdata(FuType.lsu) := 0.U
fu.inst(0).ex.out io.memoryStage.inst0.rd_info.wdata(FuType.mou) := 0.U
io.memoryStage.inst0.ex := MuxLookup(io.executeStage.inst0.inst_info.fusel, fu.inst(0).ex.out)(
Seq(
FuType.lsu -> accessMemCtrl.inst(0).ex.out,
FuType.csr -> io.csr.out.ex(0)
)
) )
io.memoryStage.inst1.pc := io.executeStage.inst1.pc io.memoryStage.inst1.pc := io.executeStage.inst1.pc
io.memoryStage.inst1.inst_info := io.executeStage.inst1.inst_info io.memoryStage.inst1.inst_info := io.executeStage.inst1.inst_info
io.memoryStage.inst1.rd_info.wdata := fu.inst(1).result io.memoryStage.inst1.rd_info.wdata(FuType.alu) := fu.inst(1).result.alu
io.memoryStage.inst1.ex := Mux( io.memoryStage.inst1.rd_info.wdata(FuType.mdu) := fu.inst(1).result.mdu
io.executeStage.inst1.inst_info.fusel === FuType.lsu, io.memoryStage.inst1.rd_info.wdata(FuType.csr) := io.csr.out.rdata
accessMemCtrl.inst(1).ex.out, io.memoryStage.inst1.rd_info.wdata(FuType.lsu) := 0.U
fu.inst(1).ex.out io.memoryStage.inst1.rd_info.wdata(FuType.mou) := 0.U
io.memoryStage.inst1.ex := MuxLookup(io.executeStage.inst1.inst_info.fusel, fu.inst(1).ex.out)(
Seq(
FuType.lsu -> accessMemCtrl.inst(1).ex.out,
FuType.csr -> io.csr.out.ex(1)
)
) )
io.decoderUnit.forward(0).exe.wen := io.memoryStage.inst0.inst_info.reg_wen io.decoderUnit.forward(0).exe.wen := io.memoryStage.inst0.inst_info.reg_wen

View File

@ -22,7 +22,10 @@ class Fu(implicit val config: CpuConfig) extends Module {
val in = Input(new ExceptionInfo()) val in = Input(new ExceptionInfo())
val out = Output(new ExceptionInfo()) val out = Output(new ExceptionInfo())
} }
val result = Output(UInt(DATA_WID.W)) val result = Output(new Bundle {
val mdu = UInt(DATA_WID.W)
val alu = UInt(DATA_WID.W)
})
} }
) )
val csr_rdata = Input(Vec(config.fuNum, UInt(DATA_WID.W))) val csr_rdata = Input(Vec(config.fuNum, UInt(DATA_WID.W)))
@ -73,10 +76,12 @@ class Fu(implicit val config: CpuConfig) extends Module {
// (io.inst.map(_.mul_en).reduce(_ || _) && !mul.ready) // (io.inst.map(_.mul_en).reduce(_ || _) && !mul.ready)
io.stall_req := false.B io.stall_req := false.B
io.inst(0).result := Mux( io.inst(0).result.alu := Mux(
ALUOpType.isBru(io.inst(0).inst_info.op), ALUOpType.isBru(io.inst(0).inst_info.op),
io.inst(0).pc + 4.U, io.inst(0).pc + 4.U,
alu(0).io.result alu(0).io.result
) )
io.inst(1).result := alu(1).io.result io.inst(0).result.mdu := DontCare
io.inst(1).result.alu := alu(1).io.result
io.inst(1).result.mdu := DontCare
} }

View File

@ -18,13 +18,13 @@ class WriteBackUnit(implicit val config: CpuConfig) extends Module {
io.regfile(0).wen := io.writeBackStage.inst0.inst_info.reg_wen && io.regfile(0).wen := io.writeBackStage.inst0.inst_info.reg_wen &&
io.ctrl.allow_to_go && !io.writeBackStage.inst0.ex.excode.asUInt.orR io.ctrl.allow_to_go && !io.writeBackStage.inst0.ex.excode.asUInt.orR
io.regfile(0).waddr := io.writeBackStage.inst0.inst_info.reg_waddr io.regfile(0).waddr := io.writeBackStage.inst0.inst_info.reg_waddr
io.regfile(0).wdata := io.writeBackStage.inst0.rd_info.wdata io.regfile(0).wdata := io.writeBackStage.inst0.rd_info.wdata(io.writeBackStage.inst0.inst_info.fusel)
io.regfile(1).wen := io.regfile(1).wen :=
io.writeBackStage.inst1.inst_info.reg_wen && io.ctrl.allow_to_go && io.writeBackStage.inst1.inst_info.reg_wen && io.ctrl.allow_to_go &&
!io.writeBackStage.inst0.ex.excode.asUInt.orR && !io.writeBackStage.inst1.ex.excode.asUInt.orR !io.writeBackStage.inst0.ex.excode.asUInt.orR && !io.writeBackStage.inst1.ex.excode.asUInt.orR
io.regfile(1).waddr := io.writeBackStage.inst1.inst_info.reg_waddr io.regfile(1).waddr := io.writeBackStage.inst1.inst_info.reg_waddr
io.regfile(1).wdata := io.writeBackStage.inst1.rd_info.wdata io.regfile(1).wdata := io.writeBackStage.inst1.rd_info.wdata(io.writeBackStage.inst1.inst_info.fusel)
if (config.hasCommitBuffer) { if (config.hasCommitBuffer) {
val buffer = Module(new CommitBuffer()).io val buffer = Module(new CommitBuffer()).io