You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
// val memBarWrEn = Input(Bool()) // Does not exist currently, write enable is only sent via wb stage to the regFile
17
+
valexBarWrEn=Input(Bool())// NEW: Is the instruction in MEM writing?
18
+
valwbStageWrEn=Input(Bool()) // Is the instruction in WB writing? // val memBarWrEn = Input(Bool()) // Does not exist currently, write enable is only sent via wb stage to the regFile
19
19
// no mem module in task 3, hence there were no load instr (or store), write enable was always "set"
20
20
// Also no branche or jump as of now
21
21
@@ -27,7 +27,7 @@ class ForwardingUnit extends Module{
Copy file name to clipboardExpand all lines: 03_RV32I-pipeline/src/main/scala/IDstage.scala
+8-1Lines changed: 8 additions & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -63,6 +63,7 @@ class ID extends Module {
63
63
64
64
valpcSel=Output(Bool()) // Input for PC selection signal from EX stage (for branch/jump)
65
65
valtargetPC=Output(UInt(32.W)) // Output for target PC to IF stage for branch/jump
66
+
valwr_en=Output(Bool()) //
66
67
})
67
68
68
69
valopcode= io.inst(6, 0) // Extract opcode from instruction
@@ -76,7 +77,6 @@ class ID extends Module {
76
77
valimmB=Cat(io.inst(31), io.inst(7), io.inst(30, 25), io.inst(11, 8), 0.U(1.W)).asSInt.pad(32).asUInt // Extract immediate for B-type instructions, Bit 0 as it is a multiples of 2 bytes
77
78
78
79
io.uop :=NOP.asUInt // Default to NOP
79
-
io.rd_idx := rd // Output destination register index
80
80
io.XcptInvalid:=true.B// Default to invalid instruction, will be cleared for valid instructions
81
81
82
82
io.regFileReq_A.addr := rs1 // Set read address for rs1
Mux(opcode ==="b1100011".U, (io.pc + immB), 0.U(32.W)))) // Calculate target PC for JALR and B-type instructions, will be used in IF stage for PC update
95
95
96
+
// Branches (B-type) and Stores (S-type) do NOT write to registers!
97
+
valisBranch= (opcode ==="b1100011".U)
98
+
// val isStore = (opcode === "b0100011".U) // Not Implemented right now
99
+
100
+
io.wr_en :=!(isBranch) // || isStore)
101
+
io.rd_idx := rd // Output destination register index
Copy file name to clipboardExpand all lines: 03_RV32I-pipeline/src/main/scala/WBstage.scala
+2-1Lines changed: 2 additions & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -43,14 +43,15 @@ class WB extends Module {
43
43
valio=IO(newBundle {
44
44
valaluResult=Input(UInt(32.W))
45
45
valrd=Input(UInt(5.W))
46
+
valinWrEn=Input(Bool())
46
47
47
48
valregFileReq=Output(newRegFileWriteReq) // Write request to register file
48
49
valcheck_res=Output(UInt(32.W)) // Output for verification and debugging
49
50
})
50
51
51
52
io.regFileReq.addr := io.rd // Set write address to rd
52
53
io.regFileReq.data := io.aluResult // Forward aluResult to register file write port
53
-
io.regFileReq.wr_en :=true.B// Enable write for all R-type and I-type instructions (to be refined with instruction decoding)
54
+
io.regFileReq.wr_en :=io.inWrEn// Enable write for all R-type and I-type instructions, set in the ID Stage (False only in Branches and Store {not implemented yet})
54
55
55
56
io.check_res := io.aluResult // Output result for verification and debugging
exBarrier.io.inWrEn := idBarrier.io.outWrEn // Pass write enable from ID barrier to EX barrier (critical for correct forwarding behavior and to prevent hazards from writing instructions)
memBarrier.io.inWrEn := exBarrier.io.outWrEn // Pass write enable from EX barrier to MEM barrier (critical for correct forwarding behavior and to prevent hazards from writing instructions)
wbStage.io.inWrEn := memBarrier.io.outWrEn // Pass write enable from MEM barrier to WB stage (critical for correct forwarding behavior and to prevent hazards from writing instructions)
0 commit comments