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._ 292225d46eSJiawei Lin 302225d46eSJiawei Linclass SimTop(implicit p: Parameters) extends Module { 312225d46eSJiawei Lin val debugOpts = p(DebugOptionsKey) 322225d46eSJiawei Lin val useDRAMSim = debugOpts.UseDRAMSim 332225d46eSJiawei Lin 3473be64b3SJiawei Lin val l_soc = LazyModule(new XSTop()) 352225d46eSJiawei Lin val soc = Module(l_soc.module) 362225d46eSJiawei Lin 37*98c71602SJiawei Lin l_soc.module.dma <> 0.U.asTypeOf(l_soc.module.dma) 3873be64b3SJiawei Lin 3973be64b3SJiawei Lin val l_simMMIO = LazyModule(new SimMMIO(l_soc.misc.peripheralNode.in.head._2)) 402225d46eSJiawei Lin val simMMIO = Module(l_simMMIO.module) 4173be64b3SJiawei Lin l_simMMIO.io_axi4 <> soc.peripheral 422225d46eSJiawei Lin 432225d46eSJiawei Lin if(!useDRAMSim){ 442225d46eSJiawei Lin val l_simAXIMem = LazyModule(new AXI4RAMWrapper( 4573be64b3SJiawei Lin l_soc.misc.memAXI4SlaveNode, 8L * 1024 * 1024 * 1024, useBlackBox = true 462225d46eSJiawei Lin )) 472225d46eSJiawei Lin val simAXIMem = Module(l_simAXIMem.module) 4873be64b3SJiawei Lin l_simAXIMem.io_axi4 <> soc.memory 492225d46eSJiawei Lin } 502225d46eSJiawei Lin 5173be64b3SJiawei Lin soc.io.clock := clock.asBool 5273be64b3SJiawei Lin soc.io.reset := reset.asBool 53b6a21a24SYinan Xu soc.io.extIntrs := simMMIO.io.interrupt.intrVec 548130d625Srvcoresjw soc.io.sram_config := 0.U 55*98c71602SJiawei Lin soc.io.pll0_lock := true.B 56*98c71602SJiawei Lin soc.io.cacheable_check := DontCare 572225d46eSJiawei Lin 58d4aca96cSlqre val success = Wire(Bool()) 59d4aca96cSlqre val jtag = Module(new SimJTAG(tickDelay=3)(p)).connect(soc.io.systemjtag.jtag, clock, reset.asBool, ~reset.asBool, success) 60d4aca96cSlqre soc.io.systemjtag.reset := reset 61d4aca96cSlqre soc.io.systemjtag.mfr_id := 0.U(11.W) 62d4aca96cSlqre soc.io.systemjtag.part_number := 0.U(16.W) 63d4aca96cSlqre soc.io.systemjtag.version := 0.U(4.W) 64d4aca96cSlqre 652225d46eSJiawei Lin val io = IO(new Bundle(){ 662225d46eSJiawei Lin val logCtrl = new LogCtrlIO 672225d46eSJiawei Lin val perfInfo = new PerfInfoIO 682225d46eSJiawei Lin val uart = new UARTIO 6973be64b3SJiawei Lin val memAXI = if(useDRAMSim) soc.memory.cloneType else null 702225d46eSJiawei Lin }) 712225d46eSJiawei Lin 722225d46eSJiawei Lin simMMIO.io.uart <> io.uart 732225d46eSJiawei Lin 742225d46eSJiawei Lin if(useDRAMSim){ 7573be64b3SJiawei Lin io.memAXI <> soc.memory 762225d46eSJiawei Lin } 772225d46eSJiawei Lin 781545277aSYinan Xu if (!debugOpts.FPGAPlatform && (debugOpts.EnableDebug || debugOpts.EnablePerfDebug)) { 792225d46eSJiawei Lin val timer = GTimer() 802225d46eSJiawei Lin val logEnable = (timer >= io.logCtrl.log_begin) && (timer < io.logCtrl.log_end) 812225d46eSJiawei Lin ExcitingUtils.addSource(logEnable, "DISPLAY_LOG_ENABLE") 822225d46eSJiawei Lin ExcitingUtils.addSource(timer, "logTimestamp") 832225d46eSJiawei Lin } 842225d46eSJiawei Lin 851545277aSYinan Xu if (!debugOpts.FPGAPlatform && debugOpts.EnablePerfDebug) { 862225d46eSJiawei Lin val clean = io.perfInfo.clean 872225d46eSJiawei Lin val dump = io.perfInfo.dump 882225d46eSJiawei Lin ExcitingUtils.addSource(clean, "XSPERF_CLEAN") 892225d46eSJiawei Lin ExcitingUtils.addSource(dump, "XSPERF_DUMP") 902225d46eSJiawei Lin } 912225d46eSJiawei Lin 922225d46eSJiawei Lin // Check and dispaly all source and sink connections 932225d46eSJiawei Lin ExcitingUtils.fixConnections() 942225d46eSJiawei Lin ExcitingUtils.checkAndDisplay() 952225d46eSJiawei Lin} 962225d46eSJiawei Lin 972225d46eSJiawei Linobject SimTop extends App { 982225d46eSJiawei Lin override def main(args: Array[String]): Unit = { 991545277aSYinan Xu // Keep this the same as TopMain except that SimTop is used here instead of XSTop 1001545277aSYinan Xu val (config, firrtlOpts) = ArgParser.parse(args) 1011545277aSYinan Xu XiangShanStage.execute(firrtlOpts, Seq( 1021545277aSYinan Xu ChiselGeneratorAnnotation(() => { 1031545277aSYinan Xu DisableMonitors(p => new SimTop()(p))(config) 1041545277aSYinan Xu }) 1051545277aSYinan Xu )) 1062225d46eSJiawei Lin } 1072225d46eSJiawei Lin} 108