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

import chisel3._
import chisel3.util._
import xiangshan.backend._
6
import xiangshan.backend.fu.HasExceptionNO
7
import xiangshan.backend.dispatch.DispatchParameters
G
GouLingrui 已提交
8
import xiangshan.frontend._
9
import xiangshan.mem._
10
import xiangshan.cache.{DCacheParameters, ICacheParameters, L1plusCacheWrapper, L1plusCacheParameters, PTWWrapper, PTWRepeater, PTWFilter}
11
import xiangshan.cache.prefetch._
L
linjiawei 已提交
12
import chipsalliance.rocketchip.config
13
import chipsalliance.rocketchip.config.Parameters
14
import freechips.rocketchip.diplomacy.{Description, LazyModule, LazyModuleImp, ResourceAnchors, ResourceBindings, SimpleDevice}
L
LinJiawei 已提交
15
import freechips.rocketchip.tile.HasFPUParameters
16
import system.{HasSoCParameter, L1CacheErrorInfo}
L
LinJiawei 已提交
17
import utils._
L
LinJiawei 已提交
18

19 20
object hartIdCore extends (() => Int) {
  var x = 0
21

22 23
  def apply(): Int = {
    x = x + 1
24
    x - 1
25 26 27
  }
}

28
abstract class XSModule(implicit val p: Parameters) extends MultiIOModule
L
LinJiawei 已提交
29 30
  with HasXSParameter
  with HasExceptionNO
31
  with HasFPUParameters {
L
LinJiawei 已提交
32 33
  def io: Record
}
L
LinJiawei 已提交
34

35
//remove this trait after impl module logic
36 37
trait NeedImpl {
  this: RawModule =>
38
  override protected def IO[T <: Data](iodef: T): T = {
L
LinJiawei 已提交
39
    println(s"[Warn]: (${this.name}) please reomve 'NeedImpl' after implement this module")
40 41 42 43 44 45
    val io = chisel3.experimental.IO(iodef)
    io <> DontCare
    io
  }
}

46
abstract class XSBundle(implicit val p: Parameters) extends Bundle
L
LinJiawei 已提交
47 48
  with HasXSParameter

L
LinJiawei 已提交
49
case class EnviromentParameters
L
LinJiawei 已提交
50 51
(
  FPGAPlatform: Boolean = true,
Y
Yinan Xu 已提交
52
  EnableDebug: Boolean = false,
Z
zoujr 已提交
53
  EnablePerfDebug: Boolean = true,
54
  DualCore: Boolean = false
L
LinJiawei 已提交
55 56
)

57
abstract class XSCoreBase()(implicit p: config.Parameters) extends LazyModule
58
  with HasXSParameter
59
{
Y
Yinan Xu 已提交
60
  // outer facing nodes
J
jinyue110 已提交
61
  val frontend = LazyModule(new Frontend())
62 63
  val l1pluscache = LazyModule(new L1plusCacheWrapper())
  val ptw = LazyModule(new PTWWrapper())
64
  val memBlock = LazyModule(new MemBlock(
65 66
    fastWakeUpIn = intExuConfigs.filter(_.hasCertainLatency),
    slowWakeUpIn = intExuConfigs.filter(_.hasUncertainlatency) ++ fpExuConfigs,
67
    fastWakeUpOut = Seq(),
68 69
    slowWakeUpOut = loadExuConfigs,
    numIntWakeUpFp = intExuConfigs.count(_.writeFpRf)
70
  ))
71

72 73 74 75 76
}

class XSCore()(implicit p: config.Parameters) extends XSCoreBase
  with HasXSDts
{
L
linjiawei 已提交
77 78 79
  lazy val module = new XSCoreImp(this)
}

80
class XSCoreImp(outer: XSCoreBase) extends LazyModuleImp(outer)
81
  with HasXSParameter
82
  with HasSoCParameter
83
  with HasExeBlockHelper {
Y
Yinan Xu 已提交
84
  val io = IO(new Bundle {
85
    val hartId = Input(UInt(64.W))
Y
Yinan Xu 已提交
86
    val externalInterrupt = new ExternalInterruptIO
87
    val l2_pf_enable = Output(Bool())
L
ljw 已提交
88
    val l1plus_error, icache_error, dcache_error = Output(new L1CacheErrorInfo)
Y
Yinan Xu 已提交
89
  })
90

Z
ZhangZifei 已提交
91
  println(s"FPGAPlatform:${env.FPGAPlatform} EnableDebug:${env.EnableDebug}")
W
William Wang 已提交
92
  AddressSpace.checkMemmap()
93
  AddressSpace.printMemmap()
Z
ZhangZifei 已提交
94

L
LinJiawei 已提交
95
  // to fast wake up fp, mem rs
96 97
  val intBlockFastWakeUp = intExuConfigs.filter(_.hasCertainLatency)
  val intBlockSlowWakeUp = intExuConfigs.filter(_.hasUncertainlatency)
L
LinJiawei 已提交
98

99
  val ctrlBlock = Module(new CtrlBlock)
L
LinJiawei 已提交
100
  val integerBlock = Module(new IntegerBlock(
101
    fastWakeUpIn = Seq(),
102
    slowWakeUpIn = fpExuConfigs.filter(_.writeIntRf) ++ loadExuConfigs,
103
    memFastWakeUpIn  = loadExuConfigs,
104 105
    fastWakeUpOut = intBlockFastWakeUp,
    slowWakeUpOut = intBlockSlowWakeUp
L
LinJiawei 已提交
106 107
  ))
  val floatBlock = Module(new FloatBlock(
108 109
    intSlowWakeUpIn = intExuConfigs.filter(_.writeFpRf),
    memSlowWakeUpIn = loadExuConfigs,
110 111
    fastWakeUpOut = Seq(),
    slowWakeUpOut = fpExuConfigs
L
LinJiawei 已提交
112
  ))
L
linjiawei 已提交
113

J
jinyue110 已提交
114
  val frontend = outer.frontend.module
115
  val memBlock = outer.memBlock.module
J
jinyue110 已提交
116
  val l1pluscache = outer.l1pluscache.module
L
linjiawei 已提交
117
  val ptw = outer.ptw.module
L
linjiawei 已提交
118

L
ljw 已提交
119 120
  io.l1plus_error <> l1pluscache.io.error
  io.icache_error <> frontend.io.error
121 122
  io.dcache_error <> memBlock.io.error

123
  frontend.io.backend <> ctrlBlock.io.frontend
Y
Yinan Xu 已提交
124 125
  frontend.io.sfence <> integerBlock.io.fenceio.sfence
  frontend.io.tlbCsr <> integerBlock.io.csrio.tlb
126
  frontend.io.csrCtrl <> integerBlock.io.csrio.customCtrl
J
jinyue110 已提交
127

L
Lingrui98 已提交
128 129 130 131
  frontend.io.icacheMemAcq <> l1pluscache.io.req
  l1pluscache.io.resp <> frontend.io.icacheMemGrant
  l1pluscache.io.flush := frontend.io.l1plusFlush
  frontend.io.fencei := integerBlock.io.fenceio.fencei
132 133 134 135 136 137 138

  ctrlBlock.io.fromIntBlock <> integerBlock.io.toCtrlBlock
  ctrlBlock.io.fromFpBlock <> floatBlock.io.toCtrlBlock
  ctrlBlock.io.fromLsBlock <> memBlock.io.toCtrlBlock
  ctrlBlock.io.toIntBlock <> integerBlock.io.fromCtrlBlock
  ctrlBlock.io.toFpBlock <> floatBlock.io.fromCtrlBlock
  ctrlBlock.io.toLsBlock <> memBlock.io.fromCtrlBlock
139
  ctrlBlock.io.csrCtrl <> integerBlock.io.csrio.customCtrl
140

141 142
  val memBlockWakeUpInt = memBlock.io.wakeUpOutInt.slow.map(WireInit(_))
  val memBlockWakeUpFp = memBlock.io.wakeUpOutFp.slow.map(WireInit(_))
143 144
  memBlock.io.wakeUpOutInt.slow.foreach(_.ready := true.B)
  memBlock.io.wakeUpOutFp.slow.foreach(_.ready := true.B)
L
LinJiawei 已提交
145

146
  fpExuConfigs.zip(floatBlock.io.wakeUpOut.slow).filterNot(_._1.writeIntRf).map(_._2.ready := true.B)
147 148 149
  val fpBlockWakeUpInt = fpExuConfigs
    .zip(floatBlock.io.wakeUpOut.slow)
    .filter(_._1.writeIntRf)
150
    .map(_._2)
L
LinJiawei 已提交
151

152
  intExuConfigs.zip(integerBlock.io.wakeUpOut.slow).filterNot(_._1.writeFpRf).map(_._2.ready := true.B)
153 154 155
  val intBlockWakeUpFp = intExuConfigs.filter(_.hasUncertainlatency)
    .zip(integerBlock.io.wakeUpOut.slow)
    .filter(_._1.writeFpRf)
156
    .map(_._2)
L
LinJiawei 已提交
157

158 159
  integerBlock.io.wakeUpIn.slow <> fpBlockWakeUpInt ++ memBlockWakeUpInt
  integerBlock.io.toMemBlock <> memBlock.io.fromIntBlock
160
  integerBlock.io.memFastWakeUp <> memBlock.io.ldFastWakeUpInt
L
LinJiawei 已提交
161

162 163
  floatBlock.io.intWakeUpFp <> intBlockWakeUpFp
  floatBlock.io.memWakeUpFp <> memBlockWakeUpFp
164
  floatBlock.io.toMemBlock <> memBlock.io.fromFpBlock
L
LinJiawei 已提交
165 166

  val wakeUpMem = Seq(
167 168
    integerBlock.io.wakeUpOut,
    floatBlock.io.wakeUpOut,
L
LinJiawei 已提交
169 170
  )
  memBlock.io.wakeUpIn.fastUops <> wakeUpMem.flatMap(_.fastUops)
171
  memBlock.io.wakeUpIn.fast <> wakeUpMem.flatMap(_.fast)
172 173 174
  // Note: 'WireInit' is used to block 'ready's from memBlock,
  // we don't need 'ready's from memBlock
  memBlock.io.wakeUpIn.slow <> wakeUpMem.flatMap(_.slow.map(x => WireInit(x)))
175
  memBlock.io.intWakeUpFp <> floatBlock.io.intWakeUpOut
176 177
  memBlock.io.intWbOut := integerBlock.io.intWbOut
  memBlock.io.fpWbOut := floatBlock.io.fpWbOut
L
LinJiawei 已提交
178

179
  integerBlock.io.csrio.hartId <> io.hartId
180 181
  integerBlock.io.csrio.perf <> DontCare
  integerBlock.io.csrio.perf.retiredInstr <> ctrlBlock.io.roqio.toCSR.perfinfo.retiredInstr
182 183 184 185 186
  integerBlock.io.csrio.perf.bpuInfo <> ctrlBlock.io.perfInfo.bpuInfo
  integerBlock.io.csrio.perf.ctrlInfo <> ctrlBlock.io.perfInfo.ctrlInfo
  integerBlock.io.csrio.perf.memInfo <> memBlock.io.memInfo
  integerBlock.io.csrio.perf.frontendInfo <> frontend.io.frontendInfo

187 188 189 190
  integerBlock.io.csrio.fpu.fflags <> ctrlBlock.io.roqio.toCSR.fflags
  integerBlock.io.csrio.fpu.isIllegal := false.B
  integerBlock.io.csrio.fpu.dirty_fs <> ctrlBlock.io.roqio.toCSR.dirty_fs
  integerBlock.io.csrio.fpu.frm <> floatBlock.io.frm
Y
Yinan Xu 已提交
191
  integerBlock.io.csrio.exception <> ctrlBlock.io.roqio.exception
L
LinJiawei 已提交
192
  integerBlock.io.csrio.isXRet <> ctrlBlock.io.roqio.toCSR.isXRet
193
  integerBlock.io.csrio.trapTarget <> ctrlBlock.io.roqio.toCSR.trapTarget
Y
Yinan Xu 已提交
194
  integerBlock.io.csrio.interrupt <> ctrlBlock.io.roqio.toCSR.intrBitSet
Y
Yinan Xu 已提交
195 196
  integerBlock.io.csrio.memExceptionVAddr <> memBlock.io.lsqio.exceptionAddr.vaddr
  integerBlock.io.csrio.externalInterrupt <> io.externalInterrupt
197

Y
Yinan Xu 已提交
198 199 200
  integerBlock.io.fenceio.sfence <> memBlock.io.sfence
  integerBlock.io.fenceio.sbuffer <> memBlock.io.fenceToSbuffer

201
  memBlock.io.csrCtrl <> integerBlock.io.csrio.customCtrl
202
  memBlock.io.tlbCsr <> integerBlock.io.csrio.tlb
203
  memBlock.io.lsqio.roq <> ctrlBlock.io.roqio.lsq
204 205 206
  memBlock.io.lsqio.exceptionAddr.lsIdx.lqIdx := ctrlBlock.io.roqio.exception.bits.uop.lqIdx
  memBlock.io.lsqio.exceptionAddr.lsIdx.sqIdx := ctrlBlock.io.roqio.exception.bits.uop.sqIdx
  memBlock.io.lsqio.exceptionAddr.isStore := CommitType.lsInstIsStore(ctrlBlock.io.roqio.exception.bits.uop.ctrl.commitType)
207

208
  val itlbRepeater = Module(new PTWRepeater())
209
  val dtlbRepeater = Module(new PTWFilter(LoadPipelineWidth + StorePipelineWidth, PtwMissQueueSize))
210 211 212 213
  itlbRepeater.io.tlb <> frontend.io.ptw
  dtlbRepeater.io.tlb <> memBlock.io.ptw
  itlbRepeater.io.sfence <> integerBlock.io.fenceio.sfence
  dtlbRepeater.io.sfence <> integerBlock.io.fenceio.sfence
214 215
  ptw.io.tlb(0) <> itlbRepeater.io.ptw
  ptw.io.tlb(1) <> dtlbRepeater.io.ptw
Y
Yinan Xu 已提交
216
  ptw.io.sfence <> integerBlock.io.fenceio.sfence
217
  ptw.io.csr <> integerBlock.io.csrio.tlb
218

219 220
  // if l2 prefetcher use stream prefetch, it should be placed in XSCore
  assert(l2PrefetcherParameters._type == "bop")
221
  io.l2_pf_enable := integerBlock.io.csrio.customCtrl.l2_pf_enable
222

223
  val l1plus_reset_gen = Module(new ResetGen(1, !debugOpts.FPGAPlatform))
224 225
  l1pluscache.reset := l1plus_reset_gen.io.out

226
  val ptw_reset_gen = Module(new ResetGen(2, !debugOpts.FPGAPlatform))
227 228 229 230
  ptw.reset := ptw_reset_gen.io.out
  itlbRepeater.reset := ptw_reset_gen.io.out
  dtlbRepeater.reset := ptw_reset_gen.io.out

231
  val memBlock_reset_gen = Module(new ResetGen(3, !debugOpts.FPGAPlatform))
232 233
  memBlock.reset := memBlock_reset_gen.io.out

234
  val intBlock_reset_gen = Module(new ResetGen(4, !debugOpts.FPGAPlatform))
235 236
  integerBlock.reset := intBlock_reset_gen.io.out

237
  val fpBlock_reset_gen = Module(new ResetGen(5, !debugOpts.FPGAPlatform))
238 239
  floatBlock.reset := fpBlock_reset_gen.io.out

240
  val ctrlBlock_reset_gen = Module(new ResetGen(6, !debugOpts.FPGAPlatform))
241 242
  ctrlBlock.reset := ctrlBlock_reset_gen.io.out

243
  val frontend_reset_gen = Module(new ResetGen(7, !debugOpts.FPGAPlatform))
244
  frontend.reset := frontend_reset_gen.io.out
L
LinJiawei 已提交
245
}