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._ 22d4aca96cSlqreimport device.{AXI4RAMWrapper, SimJTAG} 23dc597826SJiawei Linimport freechips.rocketchip.diplomacy.{DisableMonitors, LazyModule, LazyModuleImp} 242225d46eSJiawei Linimport utils.GTimer 25a3e87608SWilliam Wangimport xiangshan.{DebugOptions, DebugOptionsKey} 26d4aca96cSlqreimport chipsalliance.rocketchip.config._ 27d4aca96cSlqreimport freechips.rocketchip.devices.debug._ 28a3e87608SWilliam Wangimport difftest._ 297ba24bbcSJiawei Linimport freechips.rocketchip.util.ElaborationArtefacts 307ba24bbcSJiawei Linimport top.TopMain.writeOutputFile 312225d46eSJiawei Lin 322225d46eSJiawei Linclass SimTop(implicit p: Parameters) extends Module { 332225d46eSJiawei Lin val debugOpts = p(DebugOptionsKey) 342225d46eSJiawei Lin val useDRAMSim = debugOpts.UseDRAMSim 352225d46eSJiawei Lin 3673be64b3SJiawei Lin val l_soc = LazyModule(new XSTop()) 372225d46eSJiawei Lin val soc = Module(l_soc.module) 383a62c537SYinan Xu // Don't allow the top-level signals to be optimized out, 393a62c537SYinan Xu // so that we can re-use this SimTop for any generated Verilog RTL. 403a62c537SYinan Xu dontTouch(soc.io) 412225d46eSJiawei Lin 4298c71602SJiawei Lin l_soc.module.dma <> 0.U.asTypeOf(l_soc.module.dma) 4373be64b3SJiawei Lin 4473be64b3SJiawei Lin val l_simMMIO = LazyModule(new SimMMIO(l_soc.misc.peripheralNode.in.head._2)) 452225d46eSJiawei Lin val simMMIO = Module(l_simMMIO.module) 4673be64b3SJiawei Lin l_simMMIO.io_axi4 <> soc.peripheral 472225d46eSJiawei Lin 482225d46eSJiawei Lin if(!useDRAMSim){ 492225d46eSJiawei Lin val l_simAXIMem = LazyModule(new AXI4RAMWrapper( 5073be64b3SJiawei Lin l_soc.misc.memAXI4SlaveNode, 8L * 1024 * 1024 * 1024, useBlackBox = true 512225d46eSJiawei Lin )) 522225d46eSJiawei Lin val simAXIMem = Module(l_simAXIMem.module) 5373be64b3SJiawei Lin l_simAXIMem.io_axi4 <> soc.memory 542225d46eSJiawei Lin } 552225d46eSJiawei Lin 5673be64b3SJiawei Lin soc.io.clock := clock.asBool 5773be64b3SJiawei Lin soc.io.reset := reset.asBool 58b6a21a24SYinan Xu soc.io.extIntrs := simMMIO.io.interrupt.intrVec 598130d625Srvcoresjw soc.io.sram_config := 0.U 6098c71602SJiawei Lin soc.io.pll0_lock := true.B 6198c71602SJiawei Lin soc.io.cacheable_check := DontCare 62*c4b44470SGuokai Chen soc.io.riscv_rst_vec.foreach(_ := 0x10000000L.U) 632225d46eSJiawei Lin 64d4aca96cSlqre val success = Wire(Bool()) 65cc358710SLinJiawei val jtag = Module(new SimJTAG(tickDelay=3)(p)).connect(soc.io.systemjtag.jtag, clock, reset.asBool, !reset.asBool, success) 66d4aca96cSlqre soc.io.systemjtag.reset := reset 67d4aca96cSlqre soc.io.systemjtag.mfr_id := 0.U(11.W) 68d4aca96cSlqre soc.io.systemjtag.part_number := 0.U(16.W) 69d4aca96cSlqre soc.io.systemjtag.version := 0.U(4.W) 70d4aca96cSlqre 712225d46eSJiawei Lin val io = IO(new Bundle(){ 722225d46eSJiawei Lin val logCtrl = new LogCtrlIO 732225d46eSJiawei Lin val perfInfo = new PerfInfoIO 742225d46eSJiawei Lin val uart = new UARTIO 7573be64b3SJiawei Lin val memAXI = if(useDRAMSim) soc.memory.cloneType else null 762225d46eSJiawei Lin }) 772225d46eSJiawei Lin 782225d46eSJiawei Lin simMMIO.io.uart <> io.uart 792225d46eSJiawei Lin 802225d46eSJiawei Lin if(useDRAMSim){ 8173be64b3SJiawei Lin io.memAXI <> soc.memory 822225d46eSJiawei Lin } 832225d46eSJiawei Lin 841545277aSYinan Xu if (!debugOpts.FPGAPlatform && (debugOpts.EnableDebug || debugOpts.EnablePerfDebug)) { 852225d46eSJiawei Lin val timer = GTimer() 862225d46eSJiawei Lin val logEnable = (timer >= io.logCtrl.log_begin) && (timer < io.logCtrl.log_end) 872225d46eSJiawei Lin ExcitingUtils.addSource(logEnable, "DISPLAY_LOG_ENABLE") 882225d46eSJiawei Lin ExcitingUtils.addSource(timer, "logTimestamp") 892225d46eSJiawei Lin } 902225d46eSJiawei Lin 911545277aSYinan Xu if (!debugOpts.FPGAPlatform && debugOpts.EnablePerfDebug) { 922225d46eSJiawei Lin val clean = io.perfInfo.clean 932225d46eSJiawei Lin val dump = io.perfInfo.dump 942225d46eSJiawei Lin ExcitingUtils.addSource(clean, "XSPERF_CLEAN") 952225d46eSJiawei Lin ExcitingUtils.addSource(dump, "XSPERF_DUMP") 962225d46eSJiawei Lin } 972225d46eSJiawei Lin 982225d46eSJiawei Lin // Check and dispaly all source and sink connections 992225d46eSJiawei Lin ExcitingUtils.fixConnections() 1002225d46eSJiawei Lin ExcitingUtils.checkAndDisplay() 1012225d46eSJiawei Lin} 1022225d46eSJiawei Lin 1032225d46eSJiawei Linobject SimTop extends App { 1042225d46eSJiawei Lin override def main(args: Array[String]): Unit = { 1051545277aSYinan Xu // Keep this the same as TopMain except that SimTop is used here instead of XSTop 106cc358710SLinJiawei val (config, firrtlOpts, firrtlComplier) = ArgParser.parse(args) 107cc358710SLinJiawei Generator.execute( 108cc358710SLinJiawei firrtlOpts, 109cc358710SLinJiawei DisableMonitors(p => new SimTop()(p))(config), 110cc358710SLinJiawei firrtlComplier 111cc358710SLinJiawei ) 1127ba24bbcSJiawei Lin ElaborationArtefacts.files.foreach{ case (extension, contents) => 1137ba24bbcSJiawei Lin writeOutputFile("./build", s"XSTop.${extension}", contents()) 1147ba24bbcSJiawei Lin } 1152225d46eSJiawei Lin } 1162225d46eSJiawei Lin} 117