修改if级逻辑
This commit is contained in:
parent
a69e4e907d
commit
1ab2644cba
|
@ -4,55 +4,41 @@ import chisel3._
|
||||||
import chisel3.util._
|
import chisel3.util._
|
||||||
import cpu.defines.Const._
|
import cpu.defines.Const._
|
||||||
import cpu.CpuConfig
|
import cpu.CpuConfig
|
||||||
|
import cpu.defines._
|
||||||
|
import cpu.pipeline.decode.FetchUnitDecodeUnit
|
||||||
|
|
||||||
class FetchUnit(
|
class ExecuteUnitFetchUnit extends Bundle {
|
||||||
implicit
|
val flush = Output(Bool())
|
||||||
val cpuConfig: CpuConfig)
|
val target = Output(UInt(XLEN.W))
|
||||||
extends Module {
|
}
|
||||||
|
|
||||||
|
class FetchUnit extends Module {
|
||||||
val io = IO(new Bundle {
|
val io = IO(new Bundle {
|
||||||
val memory = new Bundle {
|
val ctrl = new FetchUnitCtrl()
|
||||||
val flush = Input(Bool())
|
val execute = Flipped(new ExecuteUnitFetchUnit())
|
||||||
val target = Input(UInt(XLEN.W))
|
val decodeStage = Output(new FetchUnitDecodeUnit())
|
||||||
}
|
val instSram = new InstSram()
|
||||||
val decode = new Bundle {
|
|
||||||
val branch = Input(Bool())
|
|
||||||
val target = Input(UInt(XLEN.W))
|
|
||||||
}
|
|
||||||
val execute = new Bundle {
|
|
||||||
val flush = Input(Bool())
|
|
||||||
val target = Input(UInt(XLEN.W))
|
|
||||||
}
|
|
||||||
val instFifo = new Bundle {
|
|
||||||
val full = Input(Bool())
|
|
||||||
}
|
|
||||||
val iCache = new Bundle {
|
|
||||||
val inst_valid = Input(Vec(cpuConfig.instFetchNum, Bool()))
|
|
||||||
val pc = Output(UInt(XLEN.W))
|
|
||||||
val pc_next = Output(UInt(XLEN.W))
|
|
||||||
}
|
|
||||||
|
|
||||||
})
|
})
|
||||||
val pc = RegNext(io.iCache.pc_next, PC_INIT)
|
val pc = RegNext(io.instSram.addr, PC_INIT)
|
||||||
io.iCache.pc := pc
|
|
||||||
|
|
||||||
// when inst_valid(1) is true, inst_valid(0) must be true
|
|
||||||
|
|
||||||
val pc_next_temp = Wire(UInt(XLEN.W))
|
val pc_next_temp = Wire(UInt(XLEN.W))
|
||||||
|
|
||||||
pc_next_temp := pc
|
pc_next_temp := pc
|
||||||
for (i <- 0 until cpuConfig.instFetchNum) {
|
|
||||||
when(io.iCache.inst_valid(i)) {
|
|
||||||
pc_next_temp := pc + ((i + 1) * 4).U
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
io.iCache.pc_next := MuxCase(
|
io.instSram.addr := MuxCase(
|
||||||
pc_next_temp,
|
pc + 4.U,
|
||||||
Seq(
|
Seq(
|
||||||
io.memory.flush -> io.memory.target,
|
|
||||||
io.execute.flush -> io.execute.target,
|
io.execute.flush -> io.execute.target,
|
||||||
io.decode.branch -> io.decode.target,
|
!io.ctrl.allow_to_go -> pc
|
||||||
io.instFifo.full -> pc
|
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
io.decodeStage.data.valid := RegNext(!reset.asBool, false.B) & !reset.asBool
|
||||||
|
io.decodeStage.data.pc := pc
|
||||||
|
io.decodeStage.data.inst := io.instSram.rdata
|
||||||
|
io.decodeStage.data.addr_misaligned := pc(1, 0) =/= 0.U
|
||||||
|
|
||||||
|
io.instSram.en := !reset.asBool & !io.decodeStage.data.addr_misaligned
|
||||||
|
io.instSram.wen := 0.U
|
||||||
|
io.instSram.wdata := 0.U
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue