Add stall.

This commit is contained in:
Sebastian Bugge 2024-10-18 08:19:46 +02:00
parent bcbe07b601
commit 1d433dd791
Signed by: kaholaz
GPG key ID: 2EFFEDEE03519691
4 changed files with 29 additions and 7 deletions

View file

@ -119,4 +119,7 @@ class CPU extends MultiIOModule {
IDBarrier.forwardMemData := MEM.io.dataOut IDBarrier.forwardMemData := MEM.io.dataOut
IDBarrier.forwardMem := EXBarrier.writeEnableOut IDBarrier.forwardMem := EXBarrier.writeEnableOut
IDBarrier.forwardMemAddr := EXBarrier.writeAddrOut IDBarrier.forwardMemAddr := EXBarrier.writeAddrOut
// Stall
IF.io.stall := ID.io.stall
} }

View file

@ -39,6 +39,7 @@ class InstructionDecode extends MultiIOModule {
val branchType = Output(UInt(3.W)) val branchType = Output(UInt(3.W))
val jump = Output(Bool()) val jump = Output(Bool())
val returnAddr = Output(UInt(32.W)) val returnAddr = Output(UInt(32.W))
val stall = Output(Bool())
} }
) )
@ -84,13 +85,19 @@ class InstructionDecode extends MultiIOModule {
io.r2Value := registers.io.readData2 io.r2Value := registers.io.readData2
io.r2Address := registers.io.readAddress2 io.r2Address := registers.io.readAddress2
io.jump := decoder.controlSignals.jump
io.returnAddr := io.pc + 4.U
io.ALUOp := decoder.ALUop io.ALUOp := decoder.ALUop
io.branchType := decoder.branchType io.branchType := decoder.branchType
io.writeAddrOut := decoder.instruction.registerRd io.writeAddrOut := decoder.instruction.registerRd
io.writeEnableOut := decoder.controlSignals.regWrite
io.memRead := decoder.controlSignals.memRead val stallDelay = RegInit(Bool(), false.B)
io.memWrite := decoder.controlSignals.memWrite val stall = Mux(stallDelay, false.B, decoder.controlSignals.memRead)
io.stall := stall
stallDelay := stall
io.jump := Mux(stallDelay, false.B, decoder.controlSignals.jump)
io.returnAddr := io.pc + 4.U
io.writeEnableOut := Mux(stallDelay, false.B, decoder.controlSignals.regWrite)
io.memRead := Mux(stallDelay, false.B, decoder.controlSignals.memRead)
io.memWrite := Mux(stallDelay, false.B, decoder.controlSignals.memWrite)
} }

View file

@ -27,6 +27,7 @@ class InstructionFetch extends MultiIOModule {
val instruction = Output(new Instruction) val instruction = Output(new Instruction)
val branch = Input(Bool()) val branch = Input(Bool())
val branchAddress = Input(UInt(32.W)) val branchAddress = Input(UInt(32.W))
val stall = Input(Bool())
}) })
val IMEM = Module(new IMEM) val IMEM = Module(new IMEM)
@ -47,7 +48,7 @@ class InstructionFetch extends MultiIOModule {
*/ */
io.PC := PC io.PC := PC
IMEM.io.instructionAddress := PC IMEM.io.instructionAddress := PC
PC := Mux(io.branch, io.branchAddress, PC + 4.U) PC := Mux(io.stall, PC, Mux(io.branch, io.branchAddress, PC + 4.U))
val instruction = Wire(new Instruction) val instruction = Wire(new Instruction)
instruction := IMEM.io.instruction.asTypeOf(new Instruction) instruction := IMEM.io.instruction.asTypeOf(new Instruction)

View file

@ -0,0 +1,11 @@
main:
addi x1, zero, 4
lw x1, 0(x1)
lw x1, 0(x1)
addi x1, zero, 4
done
#memset 0x0, 4
#memset 0x4, 8
#memset 0x8, 12
#memset 0xc, 16
#memset 0x10, 20