|
|
|
@@ -1,6 +1,6 @@ |
|
|
|
package FiveStage |
|
|
|
import chisel3._ |
|
|
|
import chisel3.util.{ BitPat, MuxCase } |
|
|
|
import chisel3.util._ |
|
|
|
import chisel3.experimental.MultiIOModule |
|
|
|
|
|
|
|
|
|
|
|
@@ -21,6 +21,14 @@ class InstructionDecode extends MultiIOModule { |
|
|
|
/** |
|
|
|
* TODO: Your code here. |
|
|
|
*/ |
|
|
|
val PC = Input(UInt(32.W)) |
|
|
|
val instruction = Input(new Instruction) |
|
|
|
val regWriteData = Input(UInt(32.W)) |
|
|
|
|
|
|
|
val controlSignals = Output(new ControlSignals) |
|
|
|
val data1 = Output(UInt(32.W)) |
|
|
|
val data2 = Output(UInt(32.W)) |
|
|
|
val ALUop = Output(UInt(4.W)) |
|
|
|
} |
|
|
|
) |
|
|
|
|
|
|
|
@@ -39,11 +47,47 @@ class InstructionDecode extends MultiIOModule { |
|
|
|
/** |
|
|
|
* TODO: Your code here. |
|
|
|
*/ |
|
|
|
registers.io.readAddress1 := 0.U |
|
|
|
registers.io.readAddress2 := 0.U |
|
|
|
registers.io.writeEnable := false.B |
|
|
|
registers.io.writeAddress := 0.U |
|
|
|
registers.io.writeData := 0.U |
|
|
|
decoder.instruction := io.instruction |
|
|
|
|
|
|
|
registers.io.readAddress1 := io.instruction.registerRs1 |
|
|
|
registers.io.readAddress2 := io.instruction.registerRs2 |
|
|
|
registers.io.writeEnable := decoder.controlSignals.regWrite |
|
|
|
registers.io.writeAddress := io.instruction.registerRd |
|
|
|
registers.io.writeData := io.regWriteData |
|
|
|
|
|
|
|
io.controlSignals := decoder.controlSignals |
|
|
|
io.ALUop := decoder.ALUop |
|
|
|
io.data1 := 0.U |
|
|
|
io.data2 := 0.U |
|
|
|
|
|
|
|
decoder.instruction := 0.U.asTypeOf(new Instruction) |
|
|
|
switch (decoder.op1Select) { |
|
|
|
is (Op1Select.rs1) { |
|
|
|
io.data1 := registers.io.readData1 |
|
|
|
} |
|
|
|
is (Op1Select.PC) { |
|
|
|
io.data1 := io.PC |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
switch (decoder.op2Select) { |
|
|
|
is (Op2Select.rs2) { |
|
|
|
io.data2 := registers.io.readData2 |
|
|
|
} |
|
|
|
is (Op2Select.imm) { |
|
|
|
val immTypeMap = Array( |
|
|
|
ImmFormat.ITYPE -> io.instruction.immediateIType, |
|
|
|
ImmFormat.STYPE -> io.instruction.immediateSType, |
|
|
|
ImmFormat.BTYPE -> io.instruction.immediateBType, |
|
|
|
ImmFormat.UTYPE -> io.instruction.immediateUType, |
|
|
|
ImmFormat.JTYPE -> io.instruction.immediateJType, |
|
|
|
ImmFormat.SHAMT -> 0.S, // TODO: Implement SHAMT |
|
|
|
) |
|
|
|
|
|
|
|
io.data2 := MuxLookup( |
|
|
|
decoder.immType, |
|
|
|
0.S, |
|
|
|
immTypeMap, |
|
|
|
).pad(32).asUInt |
|
|
|
} |
|
|
|
} |
|
|
|
} |