Skip to content

Commit e888253

Browse files
committed
feat(top): adapt difftest interfaces for FPGA difftest
This change moves XSDiffTop instantiation into the Difftest for fpgaDiff. DiffTop will generated with a SimTop wrapper, where DiffTest outputs, together with XSTop's IO ports, AXI4 buses of memory/peripheral/DMA will be exposed for external connection. Temporarily, we still expose XSNoCDiffTop with appended Difftest IOs, and generate XSTop and XSNoCTop with internal Difftest DPI-C, so as to avoid extra TopIOs and mixed generated files. We will try to refactor them like DiffTop later.(i.e. generate with a seperated Difftest)
1 parent 13bec12 commit e888253

File tree

2 files changed

+20
-10
lines changed

2 files changed

+20
-10
lines changed

src/main/scala/top/Top.scala

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ package top
2020
import chisel3._
2121
import chisel3.util._
2222
import chisel3.experimental.dataview._
23-
import difftest.DifftestModule
23+
import difftest.{DifftestModule, DifftestTopIO, HasDiffTestInterfaces}
2424
import xiangshan._
2525
import utils._
2626
import utility._
@@ -43,10 +43,9 @@ import freechips.rocketchip.interrupts._
4343
import freechips.rocketchip.amba.axi4._
4444
import freechips.rocketchip.jtag.JTAGIO
4545
import chisel3.experimental.annotate
46-
import scala.collection.mutable.{Map}
4746

48-
import difftest.common.DifftestWiring
49-
import difftest.util.Profile
47+
import scala.collection.mutable.Map
48+
import difftest.gateway.Gateway
5049

5150
abstract class BaseXSSoc()(implicit p: Parameters) extends LazyModule
5251
with HasSoCParameter
@@ -460,11 +459,19 @@ class XSTop()(implicit p: Parameters) extends BaseXSSoc()
460459
class XSTileDiffTop(implicit p: Parameters) extends XSTop {
461460
//TODO: need to keep the same module name as XSNoCDiffTop
462461
override lazy val desiredName: String = "XSTop"
463-
class XSTileDiffTopImp(wrapper: XSTop) extends XSTopImp(wrapper) {
464-
DifftestWiring.createAndConnectExtraIOs()
465-
Profile.generateJson("XiangShan")
466-
}
467462

463+
class XSTileDiffTopImp(wrapper: XSTop) extends XSTopImp(wrapper) with HasDiffTestInterfaces {
464+
override def cpuName: Option[String] = Some("XiangShan")
465+
override def connectTopIOs(difftest: DifftestTopIO): Seq[Data] = {
466+
Seq(wrapper.nmi.getWrappedValue) ++
467+
dma.toSeq ++
468+
Seq(
469+
memory,
470+
peripheral,
471+
io
472+
)
473+
}
474+
}
468475
override lazy val module = new XSTileDiffTopImp(this)
469476
}
470477

@@ -484,7 +491,7 @@ object TopMain extends App {
484491
Generator.execute(firrtlOpts, soc.module, firtoolOpts)
485492
} else if (config(SoCParamsKey).UseXSTileDiffTop) {
486493
val soc = DisableMonitors(p => LazyModule(new XSTileDiffTop()(p)))(config)
487-
Generator.execute(firrtlOpts, soc.module, firtoolOpts)
494+
Generator.execute(firrtlOpts, DifftestModule.top(soc.module), firtoolOpts)
488495
} else {
489496
val soc = if (config(SoCParamsKey).UseXSNoCTop)
490497
DisableMonitors(p => LazyModule(new XSNoCTop()(p)))(config)
@@ -495,6 +502,8 @@ object TopMain extends App {
495502

496503
// generate difftest bundles (w/o DifftestTopIO)
497504
if (enableDifftest) {
505+
// TODO: Temporarily force XSTop to use internal DPI-C; will later split Top and Difftest like DiffTop
506+
Gateway.setConfig("U")
498507
DifftestModule.collect("XiangShan")
499508
}
500509
}

src/test/scala/top/SimTop.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ class XiangShanSim(implicit p: Parameters) extends Module with HasDiffTestInterf
9393
val uart = IO(new UARTIO)
9494
simMMIO.io.uart <> uart
9595

96-
override def connectTopIOs(difftest: DifftestTopIO): Unit = {
96+
override def connectTopIOs(difftest: DifftestTopIO): Seq[Data] = {
9797
difftest.uart <> uart
9898

9999
val hasPerf = !debugOpts.FPGAPlatform && debugOpts.EnablePerfDebug
@@ -105,6 +105,7 @@ class XiangShanSim(implicit p: Parameters) extends Module with HasDiffTestInterf
105105
val dump = if (hasPerf) WireDefault(difftest.perfCtrl.dump) else WireDefault(false.B)
106106

107107
XSLog.collect(timer, logEnable, clean, dump)
108+
Seq.empty
108109
}
109110
}
110111

0 commit comments

Comments
 (0)