fix: Fix FetchUnit PC initialization issue

This commit is contained in:
Liphen 2024-05-08 16:56:28 +08:00
parent 9862402688
commit ed586e41b6
1 changed files with 15 additions and 2 deletions

View File

@ -13,7 +13,20 @@ class FetchUnit extends Module {
val instSram = new InstSram()
})
val pc = RegEnable(io.instSram.addr, (PC_INIT - 4.U), io.decodeStage.data.valid)
val boot :: send :: recieve :: Nil = Enum(3)
val state = RegInit(boot)
switch(state) {
is(boot) {
state := send
}
is(send) {
state := recieve
}
is(recieve) {}
}
val pc = RegEnable(io.instSram.addr, (PC_INIT - 4.U), state =/= boot)
io.instSram.addr := MuxCase(
pc + 4.U,
@ -23,7 +36,7 @@ class FetchUnit extends Module {
)
)
io.decodeStage.data.valid := RegNext(!reset.asBool, false.B) & !reset.asBool
io.decodeStage.data.valid := state === recieve
io.decodeStage.data.pc := pc
io.decodeStage.data.inst := io.instSram.rdata
io.decodeStage.data.addr_misaligned := pc(1, 0) =/= 0.U