2016-11-28 01:16:37 +01:00
|
|
|
// See LICENSE.SiFive for license details.
|
2016-08-16 07:03:03 +02:00
|
|
|
|
|
|
|
package rocketchip
|
|
|
|
|
|
|
|
import Chisel._
|
2016-11-18 23:05:14 +01:00
|
|
|
import config._
|
2016-08-16 07:03:03 +02:00
|
|
|
import junctions._
|
2016-11-16 03:27:52 +01:00
|
|
|
import diplomacy._
|
|
|
|
import coreplex._
|
2016-11-18 00:38:11 +01:00
|
|
|
import uncore.axi4._
|
2017-03-28 06:19:08 +02:00
|
|
|
import jtag.JTAGIO
|
2016-08-16 07:03:03 +02:00
|
|
|
|
2016-12-02 02:46:52 +01:00
|
|
|
class TestHarness()(implicit p: Parameters) extends Module {
|
2016-08-16 07:03:03 +02:00
|
|
|
val io = new Bundle {
|
|
|
|
val success = Bool(OUTPUT)
|
|
|
|
}
|
2017-04-03 22:31:35 +02:00
|
|
|
|
2016-11-23 00:01:45 +01:00
|
|
|
val dut = Module(LazyModule(new ExampleRocketTop).module)
|
2017-06-02 01:06:36 +02:00
|
|
|
dut.reset := reset | dut.debug.ndreset
|
2017-04-03 22:31:35 +02:00
|
|
|
|
2017-06-02 01:06:36 +02:00
|
|
|
dut.tieOffInterrupts()
|
|
|
|
dut.connectSimAXIMem()
|
|
|
|
dut.connectSimAXIMMIO()
|
|
|
|
dut.tieOffAXI4SlavePort()
|
|
|
|
dut.connectDebug(clock, reset, io.success)
|
2016-08-16 07:03:03 +02:00
|
|
|
}
|
|
|
|
|
2017-01-19 23:42:02 +01:00
|
|
|
class SimAXIMem(channels: Int, forceSize: BigInt = 0)(implicit p: Parameters) extends LazyModule {
|
2016-11-18 00:38:11 +01:00
|
|
|
val config = p(ExtMem)
|
2017-01-19 23:42:02 +01:00
|
|
|
val totalSize = if (forceSize > 0) forceSize else BigInt(config.size)
|
|
|
|
val size = totalSize / channels
|
|
|
|
require(totalSize % channels == 0)
|
2016-08-16 07:03:03 +02:00
|
|
|
|
2017-01-19 23:42:02 +01:00
|
|
|
val node = AXI4BlindInputNode(Seq.fill(channels) {
|
2017-06-03 00:09:35 +02:00
|
|
|
AXI4MasterPortParameters(Seq(AXI4MasterParameters(
|
|
|
|
name = "dut",
|
|
|
|
id = IdRange(0, 1 << config.idBits))))})
|
2017-01-19 23:42:02 +01:00
|
|
|
|
|
|
|
for (i <- 0 until channels) {
|
|
|
|
val sram = LazyModule(new AXI4RAM(AddressSet(0, size-1), beatBytes = config.beatBytes))
|
2017-04-21 03:54:50 +02:00
|
|
|
sram.node := AXI4Buffer()(AXI4Fragmenter()(node))
|
2017-01-19 23:42:02 +01:00
|
|
|
}
|
2016-08-16 07:03:03 +02:00
|
|
|
|
2016-11-18 00:38:11 +01:00
|
|
|
lazy val module = new LazyModuleImp(this) {
|
|
|
|
val io = new Bundle {
|
2016-11-23 01:58:24 +01:00
|
|
|
val axi4 = node.bundleIn
|
2016-08-16 07:03:03 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
class SimDTM(implicit p: Parameters) extends BlackBox {
|
|
|
|
val io = new Bundle {
|
|
|
|
val clk = Clock(INPUT)
|
|
|
|
val reset = Bool(INPUT)
|
2017-03-28 06:19:08 +02:00
|
|
|
val debug = new uncore.devices.DMIIO
|
2016-08-16 07:03:03 +02:00
|
|
|
val exit = UInt(OUTPUT, 32)
|
|
|
|
}
|
2016-08-19 18:46:43 +02:00
|
|
|
|
2017-03-28 06:19:08 +02:00
|
|
|
def connect(tbclk: Clock, tbreset: Bool, dutio: uncore.devices.ClockedDMIIO, tbsuccess: Bool) = {
|
2016-09-02 03:38:39 +02:00
|
|
|
io.clk := tbclk
|
|
|
|
io.reset := tbreset
|
2017-03-29 06:13:45 +02:00
|
|
|
dutio.dmi <> io.debug
|
2017-03-28 06:19:08 +02:00
|
|
|
dutio.dmiClock := tbclk
|
|
|
|
dutio.dmiReset := tbreset
|
2016-08-19 18:46:43 +02:00
|
|
|
|
2016-11-16 03:27:52 +01:00
|
|
|
tbsuccess := io.exit === UInt(1)
|
2016-09-29 01:10:32 +02:00
|
|
|
when (io.exit >= UInt(2)) {
|
|
|
|
printf("*** FAILED *** (exit code = %d)\n", io.exit >> UInt(1))
|
2016-09-02 03:38:39 +02:00
|
|
|
stop(1)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2016-08-19 18:46:43 +02:00
|
|
|
|
2016-09-02 03:38:39 +02:00
|
|
|
class JTAGVPI(implicit val p: Parameters) extends BlackBox {
|
2016-08-19 18:46:43 +02:00
|
|
|
val io = new Bundle {
|
2017-03-28 06:19:08 +02:00
|
|
|
val jtag = new JTAGIO(hasTRSTn = false)
|
2016-08-19 18:46:43 +02:00
|
|
|
val enable = Bool(INPUT)
|
|
|
|
val init_done = Bool(INPUT)
|
|
|
|
}
|
2016-09-02 03:38:39 +02:00
|
|
|
|
2017-03-28 06:19:08 +02:00
|
|
|
def connect(dutio: JTAGIO, jtag_reset: Bool, tbreset: Bool, tbsuccess: Bool) = {
|
2016-09-02 03:38:39 +02:00
|
|
|
dutio <> io.jtag
|
|
|
|
|
2017-03-28 06:19:08 +02:00
|
|
|
dutio.TRSTn.foreach{ _:= false.B}
|
|
|
|
jtag_reset := tbreset
|
2016-09-02 03:38:39 +02:00
|
|
|
|
2017-03-28 06:19:08 +02:00
|
|
|
io.enable := ~tbreset
|
2016-09-02 03:38:39 +02:00
|
|
|
io.init_done := ~tbreset
|
|
|
|
|
|
|
|
// Success is determined by the gdbserver
|
|
|
|
// which is controlling this simulation.
|
|
|
|
tbsuccess := Bool(false)
|
|
|
|
}
|
2016-08-19 18:46:43 +02:00
|
|
|
}
|