Skip to content

Commit

Permalink
Merge branch 'litex-privileged-debug' into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
Dolu1990 committed Sep 8, 2023
2 parents 3739b9a + 9fd127d commit ff922ec
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 11 deletions.
77 changes: 67 additions & 10 deletions src/main/scala/vexriscv/demo/smp/VexRiscvSmpCluster.scala
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import spinal.lib.com.jtag.xilinx.Bscane2BmbMasterGenerator
import spinal.lib.generator._
import spinal.core.fiber._
import spinal.idslplugin.PostInitCallback
import spinal.lib.cpu.riscv.debug.{DebugModule, DebugModuleCpuConfig, DebugModuleParameter, DebugTransportModuleParameter, DebugTransportModuleTunneled}
import spinal.lib.misc.plic.PlicMapping
import spinal.lib.system.debugger.SystemDebuggerConfig
import vexriscv.ip.{DataCacheAck, DataCacheConfig, DataCacheMemBus, InstructionCache, InstructionCacheConfig}
Expand All @@ -30,7 +31,8 @@ case class VexRiscvSmpClusterParameter(cpuConfigs : Seq[VexRiscvConfig],
withExclusiveAndInvalidation : Boolean,
forcePeripheralWidth : Boolean = true,
outOfOrderDecoder : Boolean = true,
fpu : Boolean = false)
fpu : Boolean = false,
privilegedDebug : Boolean = false)

class VexRiscvSmpClusterBase(p : VexRiscvSmpClusterParameter) extends Area with PostInitCallback{
val cpuCount = p.cpuConfigs.size
Expand All @@ -52,10 +54,12 @@ class VexRiscvSmpClusterBase(p : VexRiscvSmpClusterParameter) extends Area with

implicit val interconnect = BmbInterconnectGenerator()

val debugBridge = debugCd.outputClockDomain on JtagInstructionDebuggerGenerator(p.jtagHeaderIgnoreWidth)
debugBridge.jtagClockDomain.load(ClockDomain.external("jtag", withReset = false))
val customDebug = !p.privilegedDebug generate new Area {
val debugBridge = debugCd.outputClockDomain on JtagInstructionDebuggerGenerator(p.jtagHeaderIgnoreWidth)
debugBridge.jtagClockDomain.load(ClockDomain.external("jtag", withReset = false))

val debugPort = Handle(debugBridge.logic.jtagBridge.io.ctrl.toIo)
val debugPort = Handle(debugBridge.logic.jtagBridge.io.ctrl.toIo).setName("debugPort")
}

val dBusCoherent = BmbBridgeGenerator()
val dBusNonCoherent = BmbBridgeGenerator()
Expand All @@ -80,12 +84,65 @@ class VexRiscvSmpClusterBase(p : VexRiscvSmpClusterParameter) extends Area with
interconnect.addConnection(
cpu.dBus -> List(dBusCoherent.bmb)
)
cpu.enableDebugBmb(
debugCd = debugCd.outputClockDomain,
resetCd = systemCd,
mapping = SizeMapping(cpuId*0x1000, 0x1000)

if(!p.privilegedDebug) {
cpu.enableDebugBmb(
debugCd = debugCd.outputClockDomain,
resetCd = systemCd,
mapping = SizeMapping(cpuId * 0x1000, 0x1000)
)
interconnect.addConnection(customDebug.debugBridge.bmb, cpu.debugBmb)
} else {
cpu.enableRiscvDebug(debugCd.outputClockDomain, systemCd)
}
}

val privilegedDebug = p.privilegedDebug generate new Area{
val jtagCd = ClockDomain.external("jtag", withReset = false)

val systemReset = Handle(Bool())
systemCd.relaxedReset(systemReset, ResetSensitivity.HIGH)

val p = DebugTransportModuleParameter(
addressWidth = 7,
version = 1,
idle = 7
)
interconnect.addConnection(debugBridge.bmb, cpu.debugBmb)

val logic = hardFork(debugCd.outputClockDomain on new Area {
val XLEN = 32

val dm = DebugModule(
DebugModuleParameter(
version = p.version + 1,
harts = cpuCount,
progBufSize = 2,
datacount = XLEN / 32 + cores.exists(_.cpu.config.get.FLEN == 64).toInt,
hartsConfig = cores.map(c => DebugModuleCpuConfig(
xlen = XLEN,
flen = c.cpu.config.get.FLEN,
withFpuRegAccess = c.cpu.config.get.FLEN == 64
))
)
)
systemReset := dm.io.ndmreset
for ((cpu, i) <- cores.zipWithIndex) {
val privBus = cpu.cpu.debugRiscv
privBus <> dm.io.harts(i)
privBus.dmToHart.removeAssignments() <-< dm.io.harts(i).dmToHart
}

val clintStop = (cores.map(e => e.cpu.logic.cpu.service(classOf[CsrPlugin]).stoptime).andR)

val tunnel = DebugTransportModuleTunneled(
p = p,
jtagCd = jtagCd,
debugCd = ClockDomain.current
)
dm.io.ctrl <> tunnel.io.bus

val debugPort = Handle(tunnel.io.instruction.toIo).setName("debugPort")
})
}
}

Expand Down Expand Up @@ -159,7 +216,7 @@ class VexRiscvSmpClusterWithPeripherals(p : VexRiscvSmpClusterParameter) extends
clint.cpuCount.load(cpuCount)
}


//python3 -m litex_boards.targets.digilent_nexys_video --cpu-type=vexriscv_smp --with-privileged-debug --sys-clk-freq 50000000 --cpu-count 1 --build --load
object VexRiscvSmpClusterGen {
def vexRiscvConfig(hartId : Int,
ioRange : UInt => Bool = (x => x(31 downto 28) === 0xF),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,13 +101,15 @@ class VexRiscvLitexSmpCluster(p : VexRiscvLitexSmpClusterParameter) extends VexR


object VexRiscvLitexSmpClusterCmdGen extends App {
Handle.loadHandleAsync = true
var cpuCount = 1
var iBusWidth = 64
var dBusWidth = 64
var iCacheSize = 8192
var dCacheSize = 8192
var iCacheWays = 2
var dCacheWays = 2
var privilegedDebug = false
var liteDramWidth = 128
var coherentDma = false
var wishboneMemory = false
Expand All @@ -131,6 +133,7 @@ object VexRiscvLitexSmpClusterCmdGen extends App {
opt[String]("dcache-size") action { (v, c) => dCacheSize = v.toInt }
opt[String]("icache-ways") action { (v, c) => iCacheWays = v.toInt }
opt[String]("dcache-ways") action { (v, c) => dCacheWays = v.toInt }
opt[Boolean]("privileged-debug") action { (v, c) => privilegedDebug = v }
opt[String]("litedram-width") action { (v, c) => liteDramWidth = v.toInt }
opt[String]("netlist-directory") action { (v, c) => netlistDirectory = v }
opt[String]("netlist-name") action { (v, c) => netlistName = v }
Expand Down Expand Up @@ -160,6 +163,7 @@ object VexRiscvLitexSmpClusterCmdGen extends App {
iCacheWays = iCacheWays,
dCacheWays = dCacheWays,
coherency = coherency,
privilegedDebug = privilegedDebug,
iBusRelax = true,
earlyBranch = true,
withFloat = fpu,
Expand All @@ -178,7 +182,8 @@ object VexRiscvLitexSmpClusterCmdGen extends App {
forcePeripheralWidth = !wishboneMemory || wishboneForce32b,
outOfOrderDecoder = outOfOrderDecoder,
fpu = fpu,
jtagHeaderIgnoreWidth = 0
jtagHeaderIgnoreWidth = 0,
privilegedDebug = privilegedDebug
),
liteDram = LiteDramNativeParameter(addressWidth = 32, dataWidth = liteDramWidth),
liteDramMapping = SizeMapping(0x40000000l, 0x40000000l),
Expand Down

0 comments on commit ff922ec

Please sign in to comment.