XSCore.scala 4.5 KB
Newer Older
L
LinJiawei 已提交
1 2 3 4 5 6 7
package xiangshan

import chisel3._
import chisel3.util._
import bus.simplebus._
import noop.{Cache, CacheConfig, HasExceptionNO, TLB, TLBConfig}
import xiangshan.backend._
L
LinJiawei 已提交
8 9
import xiangshan.backend.dispatch.DP1Parameters
import xiangshan.backend.exu.ExuParameters
G
GouLingrui 已提交
10
import xiangshan.frontend._
L
LinJiawei 已提交
11
import utils._
L
LinJiawei 已提交
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28

trait HasXSParameter {
  val XLEN = 64
  val HasMExtension = true
  val HasCExtension = true
  val HasDiv = true
  val HasIcache = true
  val HasDcache = true
  val EnableStoreQueue = false
  val AddrBits = 64 // AddrBits is used in some cases
  val VAddrBits = 39 // VAddrBits is Virtual Memory addr bits
  val PAddrBits = 32 // PAddrBits is Phyical Memory addr bits
  val AddrBytes = AddrBits / 8 // unused
  val DataBits = XLEN
  val DataBytes = DataBits / 8
  val HasFPU = true
  val FetchWidth = 8
G
GouLingrui 已提交
29
  val PredictWidth = FetchWidth * 2
30
  val EnableBPU = true
31
  val EnableBPD = false // enable backing predictor(like Tage) in BPUStage3
Z
zhanglinjuan 已提交
32
  val HistoryLength = 64
G
GouLingrui 已提交
33 34 35 36
  val BtbSize = 256
  // val BtbWays = 4
  val BtbBanks = PredictWidth
  // val BtbSets = BtbSize / BtbWays
37 38
  val JbtacSize = 1024
  val JbtacBanks = 8
39
  val RasSize = 16
40
  val IBufSize = 64
L
LinJiawei 已提交
41
  val DecodeWidth = 6
42
  val RenameWidth = 6
L
LinJiawei 已提交
43
  val CommitWidth = 6
44
  val BrqSize = 16
45
  val IssQueSize = 8
46
  val BrTagWidth = log2Up(BrqSize)
L
LinJiawei 已提交
47
  val NRPhyRegs = 128
48 49 50
  val PhyRegIdxWidth = log2Up(NRPhyRegs)
  val NRReadPorts = 14
  val NRWritePorts = 8
51
  val RoqSize = 32
W
William Wang 已提交
52 53
  val InnerRoqIdxWidth = log2Up(RoqSize)
  val RoqIdxWidth = InnerRoqIdxWidth + 1
54 55 56
  val IntDqDeqWidth = 4
  val FpDqDeqWidth = 4
  val LsDqDeqWidth = 4
L
LinJiawei 已提交
57
  val dp1Paremeters = DP1Parameters(
58 59 60 61
    IntDqSize = 16,
    FpDqSize = 16,
    LsDqSize = 16
  )
L
LinJiawei 已提交
62 63
  val exuParameters = ExuParameters(
    JmpCnt = 1,
64
    AluCnt = 4,
Y
Yinan Xu 已提交
65 66
    MulCnt = 1,
    MduCnt = 1,
67 68 69
    FmacCnt = 0,
    FmiscCnt = 0,
    FmiscDivSqrtCnt = 0,
Y
Yinan Xu 已提交
70 71
    LduCnt = 0,
    StuCnt = 1
72
  )
L
LinJiawei 已提交
73 74
}

L
LinJiawei 已提交
75
trait HasXSLog { this: Module =>
76
  implicit val moduleName: String = this.name
L
LinJiawei 已提交
77 78
}

L
LinJiawei 已提交
79 80 81
abstract class XSModule extends Module
  with HasXSParameter
  with HasExceptionNO
L
LinJiawei 已提交
82
  with HasXSLog
L
LinJiawei 已提交
83

84 85 86 87 88 89 90 91 92
//remove this trait after impl module logic
trait NeedImpl { this: Module =>
  override protected def IO[T <: Data](iodef: T): T = {
    val io = chisel3.experimental.IO(iodef)
    io <> DontCare
    io
  }
}

L
LinJiawei 已提交
93 94
abstract class XSBundle extends Bundle
  with HasXSParameter
95
  with HasTageParameter
L
LinJiawei 已提交
96 97 98 99

case class XSConfig
(
  FPGAPlatform: Boolean = true,
W
William Wang 已提交
100
  EnableDebug: Boolean = true
L
LinJiawei 已提交
101 102
)

L
LinJiawei 已提交
103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118
object AddressSpace extends HasXSParameter {
  // (start, size)
  // address out of MMIO will be considered as DRAM
  def mmio = List(
    (0x30000000L, 0x10000000L),  // internal devices, such as CLINT and PLIC
    (0x40000000L, 0x40000000L) // external devices
  )

  def isMMIO(addr: UInt): Bool = mmio.map(range => {
    require(isPow2(range._2))
    val bits = log2Up(range._2)
    (addr ^ range._1.U)(PAddrBits-1, bits) === 0.U
  }).reduce(_ || _)
}


L
LinJiawei 已提交
119
class XSCore(implicit p: XSConfig) extends XSModule {
L
LinJiawei 已提交
120 121 122 123 124 125 126 127 128 129 130
  val io = IO(new Bundle {
    val imem = new SimpleBusC
    val dmem = new SimpleBusC
    val mmio = new SimpleBusUC
    val frontend = Flipped(new SimpleBusUC())
  })

  io.imem <> DontCare

  val dmemXbar = Module(new SimpleBusCrossbarNto1(3))

131
  val front = Module(new Frontend)
L
LinJiawei 已提交
132 133
  val backend = Module(new Backend)

134
  front.io.backend <> backend.io.frontend
L
LinJiawei 已提交
135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153

  backend.io.memMMU.imem <> DontCare

  val dtlb = TLB(
    in = backend.io.dmem,
    mem = dmemXbar.io.in(1),
    flush = false.B,
    csrMMU = backend.io.memMMU.dmem
  )(TLBConfig(name = "dtlb", totalEntry = 64))
  dmemXbar.io.in(0) <> dtlb.io.out
  dmemXbar.io.in(2) <> io.frontend

  io.dmem <> Cache(
    in = dmemXbar.io.out,
    mmio = Seq(io.mmio),
    flush = "b00".U,
    empty = dtlb.io.cacheEmpty,
    enable = HasDcache
  )(CacheConfig(name = "dcache"))
W
William Wang 已提交
154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177

  XSDebug("(req valid, ready | resp valid, ready) \n")
  XSDebug("c-mem(%x %x %x| %x %x) c-coh(%x %x %x| %x %x) cache (%x %x %x| %x %x) tlb (%x %x %x| %x %x)\n",
    io.dmem.mem.req.valid,
    io.dmem.mem.req.ready,
    io.dmem.mem.req.bits.addr,
    io.dmem.mem.resp.valid,
    io.dmem.mem.resp.ready,
    io.dmem.coh.req.valid,
    io.dmem.coh.req.ready,
    io.dmem.coh.req.bits.addr,
    io.dmem.coh.resp.valid,
    io.dmem.coh.resp.ready,
    dmemXbar.io.out.req.valid,
    dmemXbar.io.out.req.ready,
    dmemXbar.io.out.req.bits.addr,
    dmemXbar.io.out.resp.valid,
    dmemXbar.io.out.resp.ready,
    backend.io.dmem.req.valid,
    backend.io.dmem.req.ready,
    backend.io.dmem.req.bits.addr,
    backend.io.dmem.resp.valid,
    backend.io.dmem.resp.ready
  )
L
LinJiawei 已提交
178
}