1/*************************************************************************************** 2* Copyright (c) 2020-2021 Institute of Computing Technology, Chinese Academy of Sciences 3* Copyright (c) 2020-2021 Peng Cheng Laboratory 4* 5* XiangShan is licensed under Mulan PSL v2. 6* You can use this software according to the terms and conditions of the Mulan PSL v2. 7* You may obtain a copy of Mulan PSL v2 at: 8* http://license.coscl.org.cn/MulanPSL2 9* 10* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, 11* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, 12* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. 13* 14* See the Mulan PSL v2 for more details. 15***************************************************************************************/ 16 17package xiangshan 18 19import org.chipsalliance.cde.config.{Field, Parameters} 20import chisel3._ 21import chisel3.util._ 22import huancun._ 23import system.SoCParamsKey 24import xiangshan.backend.datapath.RdConfig._ 25import xiangshan.backend.datapath.WbConfig._ 26import xiangshan.backend.dispatch.DispatchParameters 27import xiangshan.backend.exu.ExeUnitParams 28import xiangshan.backend.fu.FuConfig._ 29import xiangshan.backend.issue.{IntScheduler, IssueBlockParams, MemScheduler, SchdBlockParams, SchedulerType, VfScheduler} 30import xiangshan.backend.regfile.{IntPregParams, PregParams, VfPregParams, FakeIntPregParams} 31import xiangshan.backend.BackendParams 32import xiangshan.cache.DCacheParameters 33import xiangshan.cache.prefetch._ 34import xiangshan.frontend.{BasePredictor, BranchPredictionResp, FTB, FakePredictor, RAS, Tage, ITTage, Tage_SC, FauFTB} 35import xiangshan.frontend.icache.ICacheParameters 36import xiangshan.cache.mmu.{L2TLBParameters, TLBParameters} 37import xiangshan.frontend._ 38import xiangshan.frontend.icache.ICacheParameters 39 40import freechips.rocketchip.diplomacy.AddressSet 41import system.SoCParamsKey 42import huancun._ 43import huancun.debug._ 44import xiangshan.cache.wpu.WPUParameters 45import coupledL2._ 46import xiangshan.backend.datapath.WakeUpConfig 47import xiangshan.mem.prefetch.{PrefetcherParams, SMSParams} 48 49import scala.math.min 50 51case object XSTileKey extends Field[Seq[XSCoreParameters]] 52 53case object XSCoreParamsKey extends Field[XSCoreParameters] 54 55case class XSCoreParameters 56( 57 HasPrefetch: Boolean = false, 58 HartId: Int = 0, 59 XLEN: Int = 64, 60 VLEN: Int = 128, 61 ELEN: Int = 64, 62 HasMExtension: Boolean = true, 63 HasCExtension: Boolean = true, 64 HasDiv: Boolean = true, 65 HasICache: Boolean = true, 66 HasDCache: Boolean = true, 67 AddrBits: Int = 64, 68 VAddrBits: Int = 39, 69 HasFPU: Boolean = true, 70 HasVPU: Boolean = true, 71 HasCustomCSRCacheOp: Boolean = true, 72 FetchWidth: Int = 8, 73 AsidLength: Int = 16, 74 EnableBPU: Boolean = true, 75 EnableBPD: Boolean = true, 76 EnableRAS: Boolean = true, 77 EnableLB: Boolean = false, 78 EnableLoop: Boolean = true, 79 EnableSC: Boolean = true, 80 EnbaleTlbDebug: Boolean = false, 81 EnableJal: Boolean = false, 82 EnableFauFTB: Boolean = true, 83 UbtbGHRLength: Int = 4, 84 // HistoryLength: Int = 512, 85 EnableGHistDiff: Boolean = true, 86 EnableCommitGHistDiff: Boolean = true, 87 UbtbSize: Int = 256, 88 FtbSize: Int = 2048, 89 RasSize: Int = 16, 90 RasSpecSize: Int = 32, 91 RasCtrSize: Int = 3, 92 CacheLineSize: Int = 512, 93 FtbWays: Int = 4, 94 TageTableInfos: Seq[Tuple3[Int,Int,Int]] = 95 // Sets Hist Tag 96 // Seq(( 2048, 2, 8), 97 // ( 2048, 9, 8), 98 // ( 2048, 13, 8), 99 // ( 2048, 20, 8), 100 // ( 2048, 26, 8), 101 // ( 2048, 44, 8), 102 // ( 2048, 73, 8), 103 // ( 2048, 256, 8)), 104 Seq(( 4096, 8, 8), 105 ( 4096, 13, 8), 106 ( 4096, 32, 8), 107 ( 4096, 119, 8)), 108 ITTageTableInfos: Seq[Tuple3[Int,Int,Int]] = 109 // Sets Hist Tag 110 Seq(( 256, 4, 9), 111 ( 256, 8, 9), 112 ( 512, 13, 9), 113 ( 512, 16, 9), 114 ( 512, 32, 9)), 115 SCNRows: Int = 512, 116 SCNTables: Int = 4, 117 SCCtrBits: Int = 6, 118 SCHistLens: Seq[Int] = Seq(0, 4, 10, 16), 119 numBr: Int = 2, 120 branchPredictor: Function2[BranchPredictionResp, Parameters, Tuple2[Seq[BasePredictor], BranchPredictionResp]] = 121 ((resp_in: BranchPredictionResp, p: Parameters) => { 122 val ftb = Module(new FTB()(p)) 123 val ubtb =Module(new FauFTB()(p)) 124 // val bim = Module(new BIM()(p)) 125 val tage = Module(new Tage_SC()(p)) 126 val ras = Module(new RAS()(p)) 127 val ittage = Module(new ITTage()(p)) 128 val preds = Seq(ubtb, tage, ftb, ittage, ras) 129 preds.map(_.io := DontCare) 130 131 // ubtb.io.resp_in(0) := resp_in 132 // bim.io.resp_in(0) := ubtb.io.resp 133 // btb.io.resp_in(0) := bim.io.resp 134 // tage.io.resp_in(0) := btb.io.resp 135 // loop.io.resp_in(0) := tage.io.resp 136 ubtb.io.in.bits.resp_in(0) := resp_in 137 tage.io.in.bits.resp_in(0) := ubtb.io.out 138 ftb.io.in.bits.resp_in(0) := tage.io.out 139 ittage.io.in.bits.resp_in(0) := ftb.io.out 140 ras.io.in.bits.resp_in(0) := ittage.io.out 141 142 (preds, ras.io.out) 143 }), 144 ICacheECCForceError: Boolean = false, 145 IBufSize: Int = 48, 146 IBufNBank: Int = 6, // IBuffer bank amount, should divide IBufSize 147 DecodeWidth: Int = 6, 148 RenameWidth: Int = 6, 149 CommitWidth: Int = 6, 150 MaxUopSize: Int = 65, 151 EnableRenameSnapshot: Boolean = true, 152 RenameSnapshotNum: Int = 4, 153 FtqSize: Int = 64, 154 EnableLoadFastWakeUp: Boolean = true, // NOTE: not supported now, make it false 155 IntLogicRegs: Int = 32, 156 FpLogicRegs: Int = 32 + 1 + 1, // 1: I2F, 1: stride 157 VecLogicRegs: Int = 32 + 1 + 15, // 15: tmp, 1: vconfig 158 VCONFIG_IDX: Int = 32, 159 NRPhyRegs: Int = 192, 160 VirtualLoadQueueSize: Int = 72, 161 LoadQueueRARSize: Int = 72, 162 LoadQueueRAWSize: Int = 64, // NOTE: make sure that LoadQueueRAWSize is power of 2. 163 RollbackGroupSize: Int = 8, 164 LoadQueueReplaySize: Int = 72, 165 LoadUncacheBufferSize: Int = 20, 166 LoadQueueNWriteBanks: Int = 8, // NOTE: make sure that LoadQueueRARSize/LoadQueueRAWSize is divided by LoadQueueNWriteBanks 167 StoreQueueSize: Int = 64, 168 StoreQueueNWriteBanks: Int = 8, // NOTE: make sure that StoreQueueSize is divided by StoreQueueNWriteBanks 169 StoreQueueForwardWithMask: Boolean = true, 170 VlsQueueSize: Int = 8, 171 RobSize: Int = 160, 172 RabSize: Int = 256, 173 VTypeBufferSize: Int = 64, // used to reorder vtype 174 IssueQueueSize: Int = 24, 175 IssueQueueCompEntrySize: Int = 16, 176 dpParams: DispatchParameters = DispatchParameters( 177 IntDqSize = 16, 178 FpDqSize = 16, 179 LsDqSize = 18, 180 IntDqDeqWidth = 8, 181 FpDqDeqWidth = 6, 182 LsDqDeqWidth = 6, 183 ), 184 intPreg: PregParams = IntPregParams( 185 numEntries = 224, 186 numRead = None, 187 numWrite = None, 188 ), 189 vfPreg: VfPregParams = VfPregParams( 190 numEntries = 192, 191 numRead = Some(14), 192 numWrite = None, 193 ), 194 prefetcher: Option[PrefetcherParams] = Some(SMSParams()), 195 LoadPipelineWidth: Int = 3, 196 StorePipelineWidth: Int = 3, 197 VecLoadPipelineWidth: Int = 2, 198 VecStorePipelineWidth: Int = 2, 199 VecMemSrcInWidth: Int = 2, 200 VecMemInstWbWidth: Int = 1, 201 VecMemDispatchWidth: Int = 1, 202 StoreBufferSize: Int = 16, 203 StoreBufferThreshold: Int = 7, 204 EnsbufferWidth: Int = 2, 205 // ============ VLSU ============ 206 UsQueueSize: Int = 8, 207 VlFlowSize: Int = 32, 208 VlUopSize: Int = 32, 209 VsFlowL1Size: Int = 128, 210 VsFlowL2Size: Int = 32, 211 VsUopSize: Int = 32, 212 // ============================== 213 UncacheBufferSize: Int = 4, 214 EnableLoadToLoadForward: Boolean = false, 215 EnableFastForward: Boolean = true, 216 EnableLdVioCheckAfterReset: Boolean = true, 217 EnableSoftPrefetchAfterReset: Boolean = true, 218 EnableCacheErrorAfterReset: Boolean = true, 219 EnableAccurateLoadError: Boolean = true, 220 EnableUncacheWriteOutstanding: Boolean = false, 221 EnableStorePrefetchAtIssue: Boolean = false, 222 EnableStorePrefetchAtCommit: Boolean = false, 223 EnableAtCommitMissTrigger: Boolean = true, 224 EnableStorePrefetchSMS: Boolean = false, 225 EnableStorePrefetchSPB: Boolean = false, 226 MMUAsidLen: Int = 16, // max is 16, 0 is not supported now 227 ReSelectLen: Int = 7, // load replay queue replay select counter len 228 iwpuParameters: WPUParameters = WPUParameters( 229 enWPU = false, 230 algoName = "mmru", 231 isICache = true, 232 ), 233 dwpuParameters: WPUParameters = WPUParameters( 234 enWPU = false, 235 algoName = "mmru", 236 enCfPred = false, 237 isICache = false, 238 ), 239 itlbParameters: TLBParameters = TLBParameters( 240 name = "itlb", 241 fetchi = true, 242 useDmode = false, 243 NWays = 48, 244 ), 245 itlbPortNum: Int = 2 + ICacheParameters().prefetchPipeNum + 1, 246 ipmpPortNum: Int = 2 + ICacheParameters().prefetchPipeNum + 1, 247 ldtlbParameters: TLBParameters = TLBParameters( 248 name = "ldtlb", 249 NWays = 48, 250 outReplace = false, 251 partialStaticPMP = true, 252 outsideRecvFlush = true, 253 saveLevel = true 254 ), 255 sttlbParameters: TLBParameters = TLBParameters( 256 name = "sttlb", 257 NWays = 48, 258 outReplace = false, 259 partialStaticPMP = true, 260 outsideRecvFlush = true, 261 saveLevel = true 262 ), 263 hytlbParameters: TLBParameters = TLBParameters( 264 name = "hytlb", 265 NWays = 48, 266 outReplace = false, 267 partialStaticPMP = true, 268 outsideRecvFlush = true, 269 saveLevel = true 270 ), 271 pftlbParameters: TLBParameters = TLBParameters( 272 name = "pftlb", 273 NWays = 48, 274 outReplace = false, 275 partialStaticPMP = true, 276 outsideRecvFlush = true, 277 saveLevel = true 278 ), 279 refillBothTlb: Boolean = false, 280 btlbParameters: TLBParameters = TLBParameters( 281 name = "btlb", 282 NWays = 48, 283 ), 284 l2tlbParameters: L2TLBParameters = L2TLBParameters(), 285 NumPerfCounters: Int = 16, 286 icacheParameters: ICacheParameters = ICacheParameters( 287 tagECC = Some("parity"), 288 dataECC = Some("parity"), 289 replacer = Some("setplru"), 290 nMissEntries = 2, 291 nProbeEntries = 2, 292 nPrefetchEntries = 12, 293 nPrefBufferEntries = 32, 294 ), 295 dcacheParametersOpt: Option[DCacheParameters] = Some(DCacheParameters( 296 tagECC = Some("secded"), 297 dataECC = Some("secded"), 298 replacer = Some("setplru"), 299 nMissEntries = 16, 300 nProbeEntries = 8, 301 nReleaseEntries = 18, 302 nMaxPrefetchEntry = 6, 303 )), 304 L2CacheParamsOpt: Option[L2Param] = Some(L2Param( 305 name = "l2", 306 ways = 8, 307 sets = 1024, // default 512KB L2 308 prefetch = Some(coupledL2.prefetch.PrefetchReceiverParams()) 309 )), 310 L2NBanks: Int = 1, 311 usePTWRepeater: Boolean = false, 312 softTLB: Boolean = false, // dpi-c l1tlb debug only 313 softPTW: Boolean = false, // dpi-c l2tlb debug only 314 softPTWDelay: Int = 1 315){ 316 def vlWidth = log2Up(VLEN) + 1 317 318 val allHistLens = SCHistLens ++ ITTageTableInfos.map(_._2) ++ TageTableInfos.map(_._2) :+ UbtbGHRLength 319 val HistoryLength = allHistLens.max + numBr * FtqSize + 9 // 256 for the predictor configs now 320 321 val intSchdParams = { 322 implicit val schdType: SchedulerType = IntScheduler() 323 SchdBlockParams(Seq( 324 IssueBlockParams(Seq( 325 ExeUnitParams("ALU0", Seq(AluCfg), Seq(IntWB(port = 0, 0)), Seq(Seq(IntRD(0, 0)), Seq(IntRD(1, 0))), true, 2), 326 ExeUnitParams("BJU0", Seq(BrhCfg, JmpCfg, MulCfg, BkuCfg), Seq(IntWB(port = 4, 0)), Seq(Seq(IntRD(8, 0)), Seq(IntRD(7, 1))), true, 2), 327 ), numEntries = IssueQueueSize, numEnq = 2, numComp = IssueQueueCompEntrySize), 328 IssueBlockParams(Seq( 329 ExeUnitParams("ALU1", Seq(AluCfg), Seq(IntWB(port = 1, 0)), Seq(Seq(IntRD(2, 0)), Seq(IntRD(3, 0))), true, 2), 330 ExeUnitParams("BJU1", Seq(BrhCfg, JmpCfg, MulCfg, BkuCfg), Seq(IntWB(port = 2, 1)), Seq(Seq(IntRD(9, 0)), Seq(IntRD(5, 1))), true, 2), 331 ), numEntries = IssueQueueSize, numEnq = 2, numComp = IssueQueueCompEntrySize), 332 IssueBlockParams(Seq( 333 ExeUnitParams("ALU2", Seq(AluCfg), Seq(IntWB(port = 2, 0)), Seq(Seq(IntRD(4, 0)), Seq(IntRD(5, 0))), true, 2), 334 ExeUnitParams("BJU2", Seq(BrhCfg, JmpCfg, I2fCfg, VSetRiWiCfg, VSetRiWvfCfg, CsrCfg, FenceCfg, I2vCfg), Seq(IntWB(port = 3, 1), VfWB(4, 0)), Seq(Seq(IntRD(10, 0)), Seq(IntRD(3, 1)))), 335 ), numEntries = IssueQueueSize, numEnq = 2, numComp = IssueQueueCompEntrySize), 336 IssueBlockParams(Seq( 337 ExeUnitParams("ALU3", Seq(AluCfg), Seq(IntWB(port = 3, 0)), Seq(Seq(IntRD(6, 0)), Seq(IntRD(7, 0))), true, 2), 338 ExeUnitParams("BJU3", Seq(BrhCfg, JmpCfg, DivCfg), Seq(IntWB(port = 4, 1)), Seq(Seq(IntRD(11, 0)), Seq(IntRD(1, 1)))), 339 ), numEntries = IssueQueueSize, numEnq = 2, numComp = IssueQueueCompEntrySize), 340 ), 341 numPregs = intPreg.numEntries, 342 numDeqOutside = 0, 343 schdType = schdType, 344 rfDataWidth = intPreg.dataCfg.dataWidth, 345 numUopIn = dpParams.IntDqDeqWidth, 346 ) 347 } 348 val vfSchdParams = { 349 implicit val schdType: SchedulerType = VfScheduler() 350 SchdBlockParams(Seq( 351 IssueBlockParams(Seq( 352 ExeUnitParams("VFEX0", Seq(VfaluCfg, VfmaCfg, VialuCfg, VppuCfg, F2fCfg, F2iCfg, VSetRvfWvfCfg), Seq(VfWB(port = 0, 0), IntWB(port = 0, 1)), Seq(Seq(VfRD(1, 0)), Seq(VfRD(2, 0)), Seq(VfRD(3, 0)), Seq(VfRD(4, 0)), Seq(VfRD(5, 0)))), 353 ), numEntries = IssueQueueSize, numEnq = 2, numComp = IssueQueueCompEntrySize), 354 IssueBlockParams(Seq( 355 ExeUnitParams("VFEX1", Seq(VfaluCfg, VfmaCfg, VimacCfg, VipuCfg, F2vCfg, VfcvtCfg), Seq(VfWB(port = 1, 0), IntWB(port = 1, 1)), Seq(Seq(VfRD(7, 0)), Seq(VfRD(8, 0)), Seq(VfRD(9, 0)), Seq(VfRD(10, 0)), Seq(VfRD(11, 0)))), 356 ExeUnitParams("VFEX2", Seq(VfdivCfg, VidivCfg), Seq(VfWB(port = 2, 0)), Seq(Seq(VfRD(7, 0)), Seq(VfRD(8, 0)), Seq(VfRD(9, 0)), Seq(VfRD(10, 0)), Seq(VfRD(11, 0)))), 357 ), numEntries = IssueQueueSize, numEnq = 2, numComp = IssueQueueCompEntrySize), 358 ), 359 numPregs = vfPreg.numEntries, 360 numDeqOutside = 0, 361 schdType = schdType, 362 rfDataWidth = vfPreg.dataCfg.dataWidth, 363 numUopIn = dpParams.FpDqDeqWidth, 364 ) 365 } 366 367 val memSchdParams = { 368 implicit val schdType: SchedulerType = MemScheduler() 369 val rfDataWidth = 64 370 371 SchdBlockParams(Seq( 372 IssueBlockParams(Seq( 373 ExeUnitParams("STA0", Seq(StaCfg, MouCfg), Seq(FakeIntWB()), Seq(Seq(IntRD(3, 1)))), 374 ), numEntries = IssueQueueSize, numEnq = 2, numComp = IssueQueueCompEntrySize), 375 IssueBlockParams(Seq( 376 ExeUnitParams("STA1", Seq(StaCfg, MouCfg), Seq(FakeIntWB()), Seq(Seq(IntRD(14, 0)))), 377 ), numEntries = IssueQueueSize, numEnq = 2, numComp = IssueQueueCompEntrySize), 378 IssueBlockParams(Seq( 379 ExeUnitParams("STA2", Seq(StaCfg, MouCfg), Seq(FakeIntWB()), Seq(Seq(IntRD(15, 0)))), 380 ), numEntries = IssueQueueSize, numEnq = 2, numComp = IssueQueueCompEntrySize), 381 IssueBlockParams(Seq( 382 ExeUnitParams("LDU0", Seq(LduCfg), Seq(IntWB(5, 0), VfWB(5, 0)), Seq(Seq(IntRD(6, 0))), true, 2), 383 ), numEntries = IssueQueueSize, numEnq = 2, numComp = IssueQueueCompEntrySize), 384 IssueBlockParams(Seq( 385 ExeUnitParams("LDU1", Seq(LduCfg), Seq(IntWB(6, 0), VfWB(6, 0)), Seq(Seq(IntRD(12, 0))), true, 2), 386 ), numEntries = IssueQueueSize, numEnq = 2, numComp = IssueQueueCompEntrySize), 387 IssueBlockParams(Seq( 388 ExeUnitParams("LDU2", Seq(LduCfg), Seq(IntWB(7, 0), VfWB(7, 0)), Seq(Seq(IntRD(13, 0))), true, 2), 389 ), numEntries = IssueQueueSize, numEnq = 2, numComp = IssueQueueCompEntrySize), 390 IssueBlockParams(Seq( 391 ExeUnitParams("VLSU0", Seq(VlduCfg, VstuCfg), Seq(VfWB(3, 0)), Seq(Seq(VfRD(1, 0)), Seq(VfRD(2, 0)), Seq(VfRD(3, 0)), Seq(VfRD(4, 0)), Seq(VfRD(5, 0)))), 392 ), numEntries = IssueQueueSize, numEnq = 2, numComp = IssueQueueCompEntrySize), 393 IssueBlockParams(Seq( 394 ExeUnitParams("STD0", Seq(StdCfg, MoudCfg), Seq(), Seq(Seq(IntRD(13, 1), VfRD(6, 0)))), 395 ), numEntries = IssueQueueSize, numEnq = 2, numComp = IssueQueueCompEntrySize), 396 IssueBlockParams(Seq( 397 ExeUnitParams("STD1", Seq(StdCfg, MoudCfg), Seq(), Seq(Seq(IntRD(5, 1), VfRD(10, Int.MaxValue)))), 398 ), numEntries = IssueQueueSize, numEnq = 2, numComp = IssueQueueCompEntrySize), 399 IssueBlockParams(Seq( 400 ExeUnitParams("STD2", Seq(StdCfg, MoudCfg), Seq(), Seq(Seq(IntRD(9, 1), VfRD(10, Int.MaxValue)))), 401 ), numEntries = IssueQueueSize, numEnq = 2, numComp = IssueQueueCompEntrySize), 402 ), 403 numPregs = intPreg.numEntries max vfPreg.numEntries, 404 numDeqOutside = 0, 405 schdType = schdType, 406 rfDataWidth = rfDataWidth, 407 numUopIn = dpParams.LsDqDeqWidth, 408 ) 409 } 410 411 def PregIdxWidthMax = intPreg.addrWidth max vfPreg.addrWidth 412 413 def iqWakeUpParams = { 414 Seq( 415 WakeUpConfig( 416 Seq("ALU0", "ALU1", "ALU2", "ALU3", "LDU0", "LDU1", "LDU2", "BJU0", "BJU1") -> 417 Seq("ALU0", "BJU0", "ALU1", "BJU1", "ALU2", "BJU2", "ALU3", "BJU3", "LDU0", "LDU1", "LDU2", "STA0", "STA1", "STA2", "STD0", "STD1", "STD2") 418 ), 419 ).flatten 420 } 421 422 def fakeIntPreg = FakeIntPregParams(intPreg.numEntries, intPreg.numRead, intPreg.numWrite) 423 424 val backendParams: BackendParams = backend.BackendParams( 425 Map( 426 IntScheduler() -> intSchdParams, 427 VfScheduler() -> vfSchdParams, 428 MemScheduler() -> memSchdParams, 429 ), 430 Seq( 431 intPreg, 432 vfPreg, 433 fakeIntPreg 434 ), 435 iqWakeUpParams, 436 ) 437} 438 439case object DebugOptionsKey extends Field[DebugOptions] 440 441case class DebugOptions 442( 443 FPGAPlatform: Boolean = false, 444 EnableDifftest: Boolean = false, 445 AlwaysBasicDiff: Boolean = true, 446 EnableDebug: Boolean = false, 447 EnablePerfDebug: Boolean = true, 448 UseDRAMSim: Boolean = false, 449 EnableConstantin: Boolean = false, 450 EnableChiselDB: Boolean = false, 451 AlwaysBasicDB: Boolean = true, 452 EnableTopDown: Boolean = false, 453 EnableRollingDB: Boolean = false 454) 455 456trait HasXSParameter { 457 458 implicit val p: Parameters 459 460 val PAddrBits = p(SoCParamsKey).PAddrBits // PAddrBits is Phyical Memory addr bits 461 462 val coreParams = p(XSCoreParamsKey) 463 val env = p(DebugOptionsKey) 464 465 val XLEN = coreParams.XLEN 466 val VLEN = coreParams.VLEN 467 val ELEN = coreParams.ELEN 468 val minFLen = 32 469 val fLen = 64 470 def xLen = XLEN 471 472 val HasMExtension = coreParams.HasMExtension 473 val HasCExtension = coreParams.HasCExtension 474 val HasDiv = coreParams.HasDiv 475 val HasIcache = coreParams.HasICache 476 val HasDcache = coreParams.HasDCache 477 val AddrBits = coreParams.AddrBits // AddrBits is used in some cases 478 val VAddrBits = coreParams.VAddrBits // VAddrBits is Virtual Memory addr bits 479 val AsidLength = coreParams.AsidLength 480 val ReSelectLen = coreParams.ReSelectLen 481 val AddrBytes = AddrBits / 8 // unused 482 val DataBits = XLEN 483 val DataBytes = DataBits / 8 484 val VDataBytes = VLEN / 8 485 val HasFPU = coreParams.HasFPU 486 val HasVPU = coreParams.HasVPU 487 val HasCustomCSRCacheOp = coreParams.HasCustomCSRCacheOp 488 val FetchWidth = coreParams.FetchWidth 489 val PredictWidth = FetchWidth * (if (HasCExtension) 2 else 1) 490 val EnableBPU = coreParams.EnableBPU 491 val EnableBPD = coreParams.EnableBPD // enable backing predictor(like Tage) in BPUStage3 492 val EnableRAS = coreParams.EnableRAS 493 val EnableLB = coreParams.EnableLB 494 val EnableLoop = coreParams.EnableLoop 495 val EnableSC = coreParams.EnableSC 496 val EnbaleTlbDebug = coreParams.EnbaleTlbDebug 497 val HistoryLength = coreParams.HistoryLength 498 val EnableGHistDiff = coreParams.EnableGHistDiff 499 val EnableCommitGHistDiff = coreParams.EnableCommitGHistDiff 500 val UbtbGHRLength = coreParams.UbtbGHRLength 501 val UbtbSize = coreParams.UbtbSize 502 val EnableFauFTB = coreParams.EnableFauFTB 503 val FtbSize = coreParams.FtbSize 504 val FtbWays = coreParams.FtbWays 505 val RasSize = coreParams.RasSize 506 val RasSpecSize = coreParams.RasSpecSize 507 val RasCtrSize = coreParams.RasCtrSize 508 509 def getBPDComponents(resp_in: BranchPredictionResp, p: Parameters) = { 510 coreParams.branchPredictor(resp_in, p) 511 } 512 val numBr = coreParams.numBr 513 val TageTableInfos = coreParams.TageTableInfos 514 val TageBanks = coreParams.numBr 515 val SCNRows = coreParams.SCNRows 516 val SCCtrBits = coreParams.SCCtrBits 517 val SCHistLens = coreParams.SCHistLens 518 val SCNTables = coreParams.SCNTables 519 520 val SCTableInfos = Seq.fill(SCNTables)((SCNRows, SCCtrBits)) zip SCHistLens map { 521 case ((n, cb), h) => (n, cb, h) 522 } 523 val ITTageTableInfos = coreParams.ITTageTableInfos 524 type FoldedHistoryInfo = Tuple2[Int, Int] 525 val foldedGHistInfos = 526 (TageTableInfos.map{ case (nRows, h, t) => 527 if (h > 0) 528 Set((h, min(log2Ceil(nRows/numBr), h)), (h, min(h, t)), (h, min(h, t-1))) 529 else 530 Set[FoldedHistoryInfo]() 531 }.reduce(_++_).toSet ++ 532 SCTableInfos.map{ case (nRows, _, h) => 533 if (h > 0) 534 Set((h, min(log2Ceil(nRows/TageBanks), h))) 535 else 536 Set[FoldedHistoryInfo]() 537 }.reduce(_++_).toSet ++ 538 ITTageTableInfos.map{ case (nRows, h, t) => 539 if (h > 0) 540 Set((h, min(log2Ceil(nRows), h)), (h, min(h, t)), (h, min(h, t-1))) 541 else 542 Set[FoldedHistoryInfo]() 543 }.reduce(_++_) ++ 544 Set[FoldedHistoryInfo]((UbtbGHRLength, log2Ceil(UbtbSize))) 545 ).toList 546 547 548 549 val CacheLineSize = coreParams.CacheLineSize 550 val CacheLineHalfWord = CacheLineSize / 16 551 val ExtHistoryLength = HistoryLength + 64 552 val ICacheECCForceError = coreParams.ICacheECCForceError 553 val IBufSize = coreParams.IBufSize 554 val IBufNBank = coreParams.IBufNBank 555 val backendParams: BackendParams = coreParams.backendParams 556 val DecodeWidth = coreParams.DecodeWidth 557 val RenameWidth = coreParams.RenameWidth 558 val CommitWidth = coreParams.CommitWidth 559 val MaxUopSize = coreParams.MaxUopSize 560 val EnableRenameSnapshot = coreParams.EnableRenameSnapshot 561 val RenameSnapshotNum = coreParams.RenameSnapshotNum 562 val FtqSize = coreParams.FtqSize 563 val EnableLoadFastWakeUp = coreParams.EnableLoadFastWakeUp 564 val IntLogicRegs = coreParams.IntLogicRegs 565 val FpLogicRegs = coreParams.FpLogicRegs 566 val VecLogicRegs = coreParams.VecLogicRegs 567 val VCONFIG_IDX = coreParams.VCONFIG_IDX 568 val IntPhyRegs = coreParams.intPreg.numEntries 569 val VfPhyRegs = coreParams.vfPreg.numEntries 570 val MaxPhyPregs = IntPhyRegs max VfPhyRegs 571 val PhyRegIdxWidth = log2Up(IntPhyRegs) max log2Up(VfPhyRegs) 572 val RobSize = coreParams.RobSize 573 val RabSize = coreParams.RabSize 574 val VTypeBufferSize = coreParams.VTypeBufferSize 575 val IntRefCounterWidth = log2Ceil(RobSize) 576 val LSQEnqWidth = coreParams.dpParams.LsDqDeqWidth 577 val LSQLdEnqWidth = LSQEnqWidth min backendParams.numLoadDp 578 val LSQStEnqWidth = LSQEnqWidth min backendParams.numStoreDp 579 val VirtualLoadQueueSize = coreParams.VirtualLoadQueueSize 580 val LoadQueueRARSize = coreParams.LoadQueueRARSize 581 val LoadQueueRAWSize = coreParams.LoadQueueRAWSize 582 val RollbackGroupSize = coreParams.RollbackGroupSize 583 val LoadQueueReplaySize = coreParams.LoadQueueReplaySize 584 val LoadUncacheBufferSize = coreParams.LoadUncacheBufferSize 585 val LoadQueueNWriteBanks = coreParams.LoadQueueNWriteBanks 586 val StoreQueueSize = coreParams.StoreQueueSize 587 val StoreQueueNWriteBanks = coreParams.StoreQueueNWriteBanks 588 val StoreQueueForwardWithMask = coreParams.StoreQueueForwardWithMask 589 val VlsQueueSize = coreParams.VlsQueueSize 590 val dpParams = coreParams.dpParams 591 592 def MemIQSizeMax = backendParams.memSchdParams.get.issueBlockParams.map(_.numEntries).max 593 def IQSizeMax = backendParams.allSchdParams.map(_.issueBlockParams.map(_.numEntries).max).max 594 595 val NumRedirect = backendParams.numRedirect 596 val BackendRedirectNum = NumRedirect + 2 //2: ldReplay + Exception 597 val FtqRedirectAheadNum = NumRedirect 598 val LoadPipelineWidth = coreParams.LoadPipelineWidth 599 val StorePipelineWidth = coreParams.StorePipelineWidth 600 val VecLoadPipelineWidth = coreParams.VecLoadPipelineWidth 601 val VecStorePipelineWidth = coreParams.VecStorePipelineWidth 602 val VecMemSrcInWidth = coreParams.VecMemSrcInWidth 603 val VecMemInstWbWidth = coreParams.VecMemInstWbWidth 604 val VecMemDispatchWidth = coreParams.VecMemDispatchWidth 605 val StoreBufferSize = coreParams.StoreBufferSize 606 val StoreBufferThreshold = coreParams.StoreBufferThreshold 607 val EnsbufferWidth = coreParams.EnsbufferWidth 608 val UsQueueSize = coreParams.UsQueueSize 609 val VlFlowSize = coreParams.VlFlowSize 610 val VlUopSize = coreParams.VlUopSize 611 val VsFlowL1Size = coreParams.VsFlowL1Size 612 val VsFlowL2Size = coreParams.VsFlowL2Size 613 val VsUopSize = coreParams.VsUopSize 614 val UncacheBufferSize = coreParams.UncacheBufferSize 615 val EnableLoadToLoadForward = coreParams.EnableLoadToLoadForward 616 val EnableFastForward = coreParams.EnableFastForward 617 val EnableLdVioCheckAfterReset = coreParams.EnableLdVioCheckAfterReset 618 val EnableSoftPrefetchAfterReset = coreParams.EnableSoftPrefetchAfterReset 619 val EnableCacheErrorAfterReset = coreParams.EnableCacheErrorAfterReset 620 val EnableAccurateLoadError = coreParams.EnableAccurateLoadError 621 val EnableUncacheWriteOutstanding = coreParams.EnableUncacheWriteOutstanding 622 val EnableStorePrefetchAtIssue = coreParams.EnableStorePrefetchAtIssue 623 val EnableStorePrefetchAtCommit = coreParams.EnableStorePrefetchAtCommit 624 val EnableAtCommitMissTrigger = coreParams.EnableAtCommitMissTrigger 625 val EnableStorePrefetchSMS = coreParams.EnableStorePrefetchSMS 626 val EnableStorePrefetchSPB = coreParams.EnableStorePrefetchSPB 627 val asidLen = coreParams.MMUAsidLen 628 val BTLBWidth = coreParams.LoadPipelineWidth + coreParams.StorePipelineWidth 629 val refillBothTlb = coreParams.refillBothTlb 630 val iwpuParam = coreParams.iwpuParameters 631 val dwpuParam = coreParams.dwpuParameters 632 val itlbParams = coreParams.itlbParameters 633 val ldtlbParams = coreParams.ldtlbParameters 634 val sttlbParams = coreParams.sttlbParameters 635 val hytlbParams = coreParams.hytlbParameters 636 val pftlbParams = coreParams.pftlbParameters 637 val btlbParams = coreParams.btlbParameters 638 val l2tlbParams = coreParams.l2tlbParameters 639 val NumPerfCounters = coreParams.NumPerfCounters 640 641 val instBytes = if (HasCExtension) 2 else 4 642 val instOffsetBits = log2Ceil(instBytes) 643 644 val icacheParameters = coreParams.icacheParameters 645 val dcacheParameters = coreParams.dcacheParametersOpt.getOrElse(DCacheParameters()) 646 647 // dcache block cacheline when lr for LRSCCycles - LRSCBackOff cycles 648 // for constrained LR/SC loop 649 val LRSCCycles = 64 650 // for lr storm 651 val LRSCBackOff = 8 652 653 // cache hierarchy configurations 654 val l1BusDataWidth = 256 655 656 // load violation predict 657 val ResetTimeMax2Pow = 20 //1078576 658 val ResetTimeMin2Pow = 10 //1024 659 // wait table parameters 660 val WaitTableSize = 1024 661 val MemPredPCWidth = log2Up(WaitTableSize) 662 val LWTUse2BitCounter = true 663 // store set parameters 664 val SSITSize = WaitTableSize 665 val LFSTSize = 32 666 val SSIDWidth = log2Up(LFSTSize) 667 val LFSTWidth = 4 668 val StoreSetEnable = true // LWT will be disabled if SS is enabled 669 val LFSTEnable = true 670 671 val PCntIncrStep: Int = 6 672 val numPCntHc: Int = 25 673 val numPCntPtw: Int = 19 674 675 val numCSRPCntFrontend = 8 676 val numCSRPCntCtrl = 8 677 val numCSRPCntLsu = 8 678 val numCSRPCntHc = 5 679 val printEventCoding = true 680 681 // Parameters for Sdtrig extension 682 protected val TriggerNum = 4 683 protected val TriggerChainMaxLength = 2 684} 685