xref: /XiangShan/src/test/scala/top/SimTop.scala (revision d4aca96cccdcdafa80dd344996e18d1978a01af7)
1c6d43980SLemover/***************************************************************************************
2c6d43980SLemover* Copyright (c) 2020-2021 Institute of Computing Technology, Chinese Academy of Sciences
3f320e0f0SYinan Xu* Copyright (c) 2020-2021 Peng Cheng Laboratory
4c6d43980SLemover*
5c6d43980SLemover* XiangShan is licensed under Mulan PSL v2.
6c6d43980SLemover* You can use this software according to the terms and conditions of the Mulan PSL v2.
7c6d43980SLemover* You may obtain a copy of Mulan PSL v2 at:
8c6d43980SLemover*          http://license.coscl.org.cn/MulanPSL2
9c6d43980SLemover*
10c6d43980SLemover* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
11c6d43980SLemover* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
12c6d43980SLemover* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
13c6d43980SLemover*
14c6d43980SLemover* See the Mulan PSL v2 for more details.
15c6d43980SLemover***************************************************************************************/
16c6d43980SLemover
172225d46eSJiawei Linpackage top
182225d46eSJiawei Lin
192225d46eSJiawei Linimport chipsalliance.rocketchip.config.{Config, Parameters}
202225d46eSJiawei Linimport chisel3.stage.ChiselGeneratorAnnotation
212225d46eSJiawei Linimport chisel3._
22*d4aca96cSlqre
23*d4aca96cSlqreimport device.{AXI4RAMWrapper, SimJTAG}
242225d46eSJiawei Linimport freechips.rocketchip.diplomacy.{LazyModule, LazyModuleImp}
252225d46eSJiawei Linimport utils.GTimer
26a3e87608SWilliam Wangimport xiangshan.{DebugOptions, DebugOptionsKey}
27*d4aca96cSlqreimport chipsalliance.rocketchip.config._
28*d4aca96cSlqreimport freechips.rocketchip.devices.debug._
29a3e87608SWilliam Wangimport difftest._
302225d46eSJiawei Lin
312225d46eSJiawei Linclass SimTop(implicit p: Parameters) extends Module {
322225d46eSJiawei Lin  val debugOpts = p(DebugOptionsKey)
332225d46eSJiawei Lin  val useDRAMSim = debugOpts.UseDRAMSim
342225d46eSJiawei Lin
352225d46eSJiawei Lin  val l_soc = LazyModule(new XSTopWithoutDMA())
362225d46eSJiawei Lin  val soc = Module(l_soc.module)
372225d46eSJiawei Lin
382225d46eSJiawei Lin  val l_simMMIO = LazyModule(new SimMMIO(l_soc.peripheralNode.in.head._2))
392225d46eSJiawei Lin  val simMMIO = Module(l_simMMIO.module)
402225d46eSJiawei Lin  l_simMMIO.connectToSoC(l_soc)
412225d46eSJiawei Lin
422225d46eSJiawei Lin  if(!useDRAMSim){
432225d46eSJiawei Lin    val l_simAXIMem = LazyModule(new AXI4RAMWrapper(
442225d46eSJiawei Lin      l_soc.memAXI4SlaveNode, 8L * 1024 * 1024 * 1024, useBlackBox = true
452225d46eSJiawei Lin    ))
462225d46eSJiawei Lin    val simAXIMem = Module(l_simAXIMem.module)
472225d46eSJiawei Lin    l_simAXIMem.connectToSoC(l_soc)
482225d46eSJiawei Lin  }
492225d46eSJiawei Lin
502225d46eSJiawei Lin  soc.io.clock := clock.asBool()
512225d46eSJiawei Lin  soc.io.reset := reset.asBool()
52b6a21a24SYinan Xu  soc.io.extIntrs := simMMIO.io.interrupt.intrVec
532225d46eSJiawei Lin
54*d4aca96cSlqre  val success = Wire(Bool())
55*d4aca96cSlqre  val jtag = Module(new SimJTAG(tickDelay=3)(p)).connect(soc.io.systemjtag.jtag, clock, reset.asBool, ~reset.asBool, success)
56*d4aca96cSlqre  soc.io.systemjtag.reset := reset
57*d4aca96cSlqre  soc.io.systemjtag.mfr_id := 0.U(11.W)
58*d4aca96cSlqre  soc.io.systemjtag.part_number := 0.U(16.W)
59*d4aca96cSlqre  soc.io.systemjtag.version := 0.U(4.W)
60*d4aca96cSlqre
612225d46eSJiawei Lin  val io = IO(new Bundle(){
622225d46eSJiawei Lin    val logCtrl = new LogCtrlIO
632225d46eSJiawei Lin    val perfInfo = new PerfInfoIO
642225d46eSJiawei Lin    val uart = new UARTIO
652225d46eSJiawei Lin    val memAXI = if(useDRAMSim) l_soc.memory.cloneType else null
662225d46eSJiawei Lin  })
672225d46eSJiawei Lin
682225d46eSJiawei Lin  simMMIO.io.uart <> io.uart
692225d46eSJiawei Lin
702225d46eSJiawei Lin  if(useDRAMSim){
712225d46eSJiawei Lin    io.memAXI <> l_soc.memory
722225d46eSJiawei Lin  }
732225d46eSJiawei Lin
742225d46eSJiawei Lin  if (debugOpts.EnableDebug || debugOpts.EnablePerfDebug) {
752225d46eSJiawei Lin    val timer = GTimer()
762225d46eSJiawei Lin    val logEnable = (timer >= io.logCtrl.log_begin) && (timer < io.logCtrl.log_end)
772225d46eSJiawei Lin    ExcitingUtils.addSource(logEnable, "DISPLAY_LOG_ENABLE")
782225d46eSJiawei Lin    ExcitingUtils.addSource(timer, "logTimestamp")
792225d46eSJiawei Lin  }
802225d46eSJiawei Lin
812225d46eSJiawei Lin  if (debugOpts.EnablePerfDebug) {
822225d46eSJiawei Lin    val clean = io.perfInfo.clean
832225d46eSJiawei Lin    val dump = io.perfInfo.dump
842225d46eSJiawei Lin    ExcitingUtils.addSource(clean, "XSPERF_CLEAN")
852225d46eSJiawei Lin    ExcitingUtils.addSource(dump, "XSPERF_DUMP")
862225d46eSJiawei Lin  }
872225d46eSJiawei Lin
882225d46eSJiawei Lin  // Check and dispaly all source and sink connections
892225d46eSJiawei Lin  ExcitingUtils.fixConnections()
902225d46eSJiawei Lin  ExcitingUtils.checkAndDisplay()
912225d46eSJiawei Lin}
922225d46eSJiawei Lin
932225d46eSJiawei Linobject SimTop extends App {
942225d46eSJiawei Lin
952225d46eSJiawei Lin  override def main(args: Array[String]): Unit = {
96175bcfe9SLinJiawei    val (config, firrtlOpts) = ArgParser.parse(args, fpga = false)
972225d46eSJiawei Lin    // generate verilog
982225d46eSJiawei Lin    XiangShanStage.execute(
9945c767e3SLinJiawei      firrtlOpts,
1002225d46eSJiawei Lin      Seq(
1012225d46eSJiawei Lin        ChiselGeneratorAnnotation(() => new SimTop()(config))
1022225d46eSJiawei Lin      )
1032225d46eSJiawei Lin    )
1042225d46eSJiawei Lin  }
1052225d46eSJiawei Lin}
106