Quellcode durchsuchen

Implement proper jumping

sindre-ex2
Sindre Stephansen vor 6 Jahren
Ursprung
Commit
793f78f2de
3 geänderte Dateien mit 22 neuen und 26 gelöschten Zeilen
  1. +3
    -6
      src/main/scala/Barriers.scala
  2. +16
    -12
      src/main/scala/CPU.scala
  3. +3
    -8
      src/main/scala/IF.scala

+ 3
- 6
src/main/scala/Barriers.scala Datei anzeigen

@@ -43,7 +43,6 @@ class Barrier[B <: Bundle](b: B) extends MultiIOModule {


class IFBundle extends Bundle { class IFBundle extends Bundle {
val PC = UInt(32.W) val PC = UInt(32.W)
val next = UInt(32.W)
val instruction = new Instruction val instruction = new Instruction
} }


@@ -51,7 +50,6 @@ class IFBundle extends Bundle {
class IFBarrier extends Barrier(new IFBundle) { class IFBarrier extends Barrier(new IFBundle) {
out.instruction := barrier(in.instruction, false) out.instruction := barrier(in.instruction, false)
out.PC := barrier(in.PC) out.PC := barrier(in.PC)
out.next := barrier(in.next)
} }




@@ -89,14 +87,13 @@ class MEMBundle extends Bundle {
val controlSignals = new ControlSignals val controlSignals = new ControlSignals
val result = UInt(32.W) val result = UInt(32.W)
val dataOut = UInt(32.W) val dataOut = UInt(32.W)
val branch = Bool()
} }




class MEMBarrier extends Barrier(new MEMBundle) { class MEMBarrier extends Barrier(new MEMBundle) {
out.PC := barrier(in.PC)
out.instruction := barrier(in.instruction)
out.controlSignals := barrier(in.controlSignals)
out.result := barrier(in.result)
default()

out.dataOut := barrier(in.dataOut, false) out.dataOut := barrier(in.dataOut, false)
} }




+ 16
- 12
src/main/scala/CPU.scala Datei anzeigen

@@ -78,7 +78,7 @@ class CPU extends MultiIOModule {


// Stage 1 // Stage 1
IFBarrier.in := IF.io IFBarrier.in := IF.io
IF.io.addr := IFBarrier.out.next
IF.io.addr := IFBarrier.out.PC + 4.U


// Stage 2 // Stage 2
ID.io.instruction := IFBarrier.out.instruction ID.io.instruction := IFBarrier.out.instruction
@@ -147,7 +147,9 @@ class CPU extends MultiIOModule {
rs2 := IDBarrier.out.reg2 rs2 := IDBarrier.out.reg2
} }


//printf(p"0x${Hexadecimal(IF.io.PC)}: Reg write: ${MEMBarrier.out.controlSignals.regWrite}, ExToR1: $exToRs1, MEMToR1: $memToRs1, wbToR1: $wbToRs1, R1: $rs1, EX: ${EXBarrier.out.result}, MEM: ${MEMBarrier.out.dataOut}, WB: ${WBBarrier.out.writeback}}\n")
//printf(p"0x${Hexadecimal(IFBarrier.out.PC)}: next: ${Hexadecimal(IF.io.addr)} freeze: $freeze, ID imm: ${IDBarrier.out.imm}, ID PC: ${IDBarrier.out.PC}, EX result: ${EXBarrier.out.result}\n")

//printf(p"0x${Hexadecimal(IF.io.PC)}: Reg write: ${MEMBarrier.out.controlSignals.regWrite}, ExToR1: $exToRs1, MEMToR1: $memToRs1, wbToR1: $wbToRs1, R1: $rs1, ID: ${IDBarrier.out.imm.asUInt} EX: ${EXBarrier.out.result}, MEM: $writeback, WB: ${WBBarrier.out.writeback}}\n")


//printf(p"0x${Hexadecimal(IF.io.PC)}: Next: 0x${Hexadecimal(IFBarrier.out.next)}, freeze: $freeze, IF: ${IFBarrier.out.instruction}, ID: ${IDBarrier.out.instruction}, EX: ${EXBarrier.out.instruction}, MEM: ${MEMBarrier.out.instruction}\n") //printf(p"0x${Hexadecimal(IF.io.PC)}: Next: 0x${Hexadecimal(IFBarrier.out.next)}, freeze: $freeze, IF: ${IFBarrier.out.instruction}, ID: ${IDBarrier.out.instruction}, EX: ${EXBarrier.out.instruction}, MEM: ${MEMBarrier.out.instruction}\n")


@@ -172,18 +174,22 @@ class CPU extends MultiIOModule {
MEM.io.writeEnable := EXBarrier.out.controlSignals.memWrite MEM.io.writeEnable := EXBarrier.out.controlSignals.memWrite
MEM.io.dataAddress := EXBarrier.out.result MEM.io.dataAddress := EXBarrier.out.result


when (EXBarrier.out.branch) {
//IF.io.addr := EXBarrier.out.result
}

MEMBarrier.in.PC := EXBarrier.out.PC MEMBarrier.in.PC := EXBarrier.out.PC
MEMBarrier.in.instruction := EXBarrier.out.instruction MEMBarrier.in.instruction := EXBarrier.out.instruction
MEMBarrier.in.controlSignals := EXBarrier.out.controlSignals MEMBarrier.in.controlSignals := EXBarrier.out.controlSignals
MEMBarrier.in.result := EXBarrier.out.result MEMBarrier.in.result := EXBarrier.out.result
MEMBarrier.in.branch := EXBarrier.out.branch
MEMBarrier.in.dataOut := MEM.io.dataOut MEMBarrier.in.dataOut := MEM.io.dataOut


// Stage 5 // Stage 5
when (freeze) {
when (EXBarrier.out.branch) {
IF.io.addr := EXBarrier.out.result
//printf(p"Jumping to ${EXBarrier.out.result}\n")
IDBarrier.clear := true.B
EXBarrier.clear := true.B
}

when (false.B && freeze) {
ID.io.writeEnable := false.B ID.io.writeEnable := false.B
ID.io.writeAddr := 0.U ID.io.writeAddr := 0.U
ID.io.writeData := 0.U ID.io.writeData := 0.U
@@ -198,13 +204,11 @@ class CPU extends MultiIOModule {
WBBarrier.in.controlSignals := MEMBarrier.out.controlSignals WBBarrier.in.controlSignals := MEMBarrier.out.controlSignals
WBBarrier.in.writeback := writeback WBBarrier.in.writeback := writeback


writeback := MEMBarrier.out.result

when (MEMBarrier.out.controlSignals.memToReg) { when (MEMBarrier.out.controlSignals.memToReg) {
writeback := MEMBarrier.out.dataOut writeback := MEMBarrier.out.dataOut
}

when (MEMBarrier.out.controlSignals.jump) {
}.elsewhen (MEMBarrier.out.controlSignals.jump) {
writeback := MEMBarrier.out.PC + 4.U writeback := MEMBarrier.out.PC + 4.U
}.otherwise {
writeback := MEMBarrier.out.result
} }
} }

+ 3
- 8
src/main/scala/IF.scala Datei anzeigen

@@ -17,13 +17,12 @@ class InstructionFetch extends MultiIOModule {
new Bundle { new Bundle {
val PC = Output(UInt()) val PC = Output(UInt())
val instruction = Output(new Instruction) val instruction = Output(new Instruction)
val next = Output(UInt(32.W))


val addr = Input(UInt(32.W)) val addr = Input(UInt(32.W))
}) })


val IMEM = Module(new IMEM) val IMEM = Module(new IMEM)
val PC = WireInit(UInt(32.W), 0.U)
val PC = WireInit(UInt(32.W), io.addr)


/** /**
* Setup. You should not change this code * Setup. You should not change this code
@@ -33,19 +32,15 @@ class InstructionFetch extends MultiIOModule {


IMEM.io.instructionAddress := PC IMEM.io.instructionAddress := PC


PC := io.addr

io.PC := RegNext(PC)
io.next := PC + 4.U
io.PC := PC
io.instruction := IMEM.io.instruction.asTypeOf(new Instruction) io.instruction := IMEM.io.instruction.asTypeOf(new Instruction)




/** /**
* Setup. You should not change this code. * Setup. You should not change this code.
*/ */
when(testHarness.IMEMsetup.setup) {
when(testHarness.IMEMsetup.setup || RegNext(testHarness.IMEMsetup.setup)) {
PC := 0.U PC := 0.U
io.next := 0.U
io.instruction := Instruction.NOP io.instruction := Instruction.NOP
} }
} }

Laden…
Abbrechen
Speichern