1
0

Merge pull request #1023 from freechipsproject/csr-cleanup

Generalize CSR file to support simpler cores
This commit is contained in:
Andrew Waterman 2017-10-04 14:04:59 -07:00 committed by GitHub
commit 5a84564203
6 changed files with 62 additions and 59 deletions

View File

@ -63,7 +63,7 @@ class DCSR extends Bundle {
} }
class MIP(implicit p: Parameters) extends CoreBundle()(p) class MIP(implicit p: Parameters) extends CoreBundle()(p)
with HasRocketCoreParameters { with HasCoreParameters {
val lip = Vec(coreParams.nLocalInterrupts, Bool()) val lip = Vec(coreParams.nLocalInterrupts, Bool())
val zero2 = Bool() val zero2 = Bool()
val debug = Bool() // keep in sync with CSR.debugIntCause val debug = Bool() // keep in sync with CSR.debugIntCause
@ -144,7 +144,7 @@ object CSR
} }
class PerfCounterIO(implicit p: Parameters) extends CoreBundle class PerfCounterIO(implicit p: Parameters) extends CoreBundle
with HasRocketCoreParameters { with HasCoreParameters {
val eventSel = UInt(OUTPUT, xLen) val eventSel = UInt(OUTPUT, xLen)
val inc = UInt(INPUT, log2Ceil(1+retireWidth)) val inc = UInt(INPUT, log2Ceil(1+retireWidth))
} }
@ -161,7 +161,7 @@ class TracedInstruction(implicit p: Parameters) extends CoreBundle {
} }
class CSRFileIO(implicit p: Parameters) extends CoreBundle class CSRFileIO(implicit p: Parameters) extends CoreBundle
with HasRocketCoreParameters { with HasCoreParameters {
val interrupts = new TileInterrupts().asInput val interrupts = new TileInterrupts().asInput
val hartid = UInt(INPUT, hartIdLen) val hartid = UInt(INPUT, hartIdLen)
val rw = new Bundle { val rw = new Bundle {
@ -190,7 +190,6 @@ class CSRFileIO(implicit p: Parameters) extends CoreBundle
val evec = UInt(OUTPUT, vaddrBitsExtended) val evec = UInt(OUTPUT, vaddrBitsExtended)
val exception = Bool(INPUT) val exception = Bool(INPUT)
val retire = UInt(INPUT, log2Up(1+retireWidth)) val retire = UInt(INPUT, log2Up(1+retireWidth))
val custom_mrw_csrs = Vec(nCustomMrwCsrs, UInt(INPUT, xLen))
val cause = UInt(INPUT, xLen) val cause = UInt(INPUT, xLen)
val pc = UInt(INPUT, vaddrBitsExtended) val pc = UInt(INPUT, vaddrBitsExtended)
val badaddr = UInt(INPUT, vaddrBitsExtended) val badaddr = UInt(INPUT, vaddrBitsExtended)
@ -208,7 +207,7 @@ class CSRFileIO(implicit p: Parameters) extends CoreBundle
} }
class CSRFile(perfEventSets: EventSets = new EventSets(Seq()))(implicit p: Parameters) extends CoreModule()(p) class CSRFile(perfEventSets: EventSets = new EventSets(Seq()))(implicit p: Parameters) extends CoreModule()(p)
with HasRocketCoreParameters { with HasCoreParameters {
val io = new CSRFileIO val io = new CSRFileIO
val reset_mstatus = Wire(init=new MStatus().fromBits(0)) val reset_mstatus = Wire(init=new MStatus().fromBits(0))
@ -223,7 +222,6 @@ class CSRFile(perfEventSets: EventSets = new EventSets(Seq()))(implicit p: Param
reset_dcsr.xdebugver := 1 reset_dcsr.xdebugver := 1
reset_dcsr.prv := PRV.M reset_dcsr.prv := PRV.M
val reg_dcsr = Reg(init=reset_dcsr) val reg_dcsr = Reg(init=reset_dcsr)
val reg_debugint = Reg(Bool())
val (supported_interrupts, delegable_interrupts) = { val (supported_interrupts, delegable_interrupts) = {
val sup = Wire(new MIP) val sup = Wire(new MIP)
@ -305,13 +303,17 @@ class CSRFile(perfEventSets: EventSets = new EventSets(Seq()))(implicit p: Param
val hpm_mask = reg_mcounteren & Mux((!usingVM).B || reg_mstatus.prv === PRV.S, delegable_counters.U, reg_scounteren) val hpm_mask = reg_mcounteren & Mux((!usingVM).B || reg_mstatus.prv === PRV.S, delegable_counters.U, reg_scounteren)
val mip = Wire(init=reg_mip) val mip = Wire(init=reg_mip)
mip.lip := (io.interrupts.lip: Seq[Bool])
mip.mtip := io.interrupts.mtip
mip.msip := io.interrupts.msip
mip.meip := io.interrupts.meip
// seip is the OR of reg_mip.seip and the actual line from the PLIC // seip is the OR of reg_mip.seip and the actual line from the PLIC
io.interrupts.seip.foreach { mip.seip := reg_mip.seip || RegNext(_) } io.interrupts.seip.foreach { mip.seip := reg_mip.seip || RegNext(_) }
mip.rocc := io.rocc_interrupt mip.rocc := io.rocc_interrupt
val read_mip = mip.asUInt & supported_interrupts val read_mip = mip.asUInt & supported_interrupts
val pending_interrupts = read_mip & reg_mie val pending_interrupts = read_mip & reg_mie
val d_interrupts = reg_debugint << CSR.debugIntCause val d_interrupts = io.interrupts.debug << CSR.debugIntCause
val m_interrupts = Mux(reg_mstatus.prv <= PRV.S || (reg_mstatus.prv === PRV.M && reg_mstatus.mie), pending_interrupts & ~reg_mideleg, UInt(0)) val m_interrupts = Mux(reg_mstatus.prv <= PRV.S || (reg_mstatus.prv === PRV.M && reg_mstatus.mie), pending_interrupts & ~reg_mideleg, UInt(0))
val s_interrupts = Mux(reg_mstatus.prv < PRV.S || (reg_mstatus.prv === PRV.S && reg_mstatus.sie), pending_interrupts & reg_mideleg, UInt(0)) val s_interrupts = Mux(reg_mstatus.prv < PRV.S || (reg_mstatus.prv === PRV.S && reg_mstatus.sie), pending_interrupts & reg_mideleg, UInt(0))
val (anyInterrupt, whichInterrupt) = chooseInterrupt(Seq(s_interrupts, m_interrupts, d_interrupts)) val (anyInterrupt, whichInterrupt) = chooseInterrupt(Seq(s_interrupts, m_interrupts, d_interrupts))
@ -343,8 +345,6 @@ class CSRFile(perfEventSets: EventSets = new EventSets(Seq()))(implicit p: Param
CSRs.mimpid -> UInt(0), CSRs.mimpid -> UInt(0),
CSRs.marchid -> UInt(0), CSRs.marchid -> UInt(0),
CSRs.mvendorid -> UInt(0), CSRs.mvendorid -> UInt(0),
CSRs.mcycle -> reg_cycle,
CSRs.minstret -> reg_instret,
CSRs.misa -> reg_misa, CSRs.misa -> reg_misa,
CSRs.mstatus -> read_mstatus, CSRs.mstatus -> read_mstatus,
CSRs.mtvec -> reg_mtvec, CSRs.mtvec -> reg_mtvec,
@ -372,6 +372,10 @@ class CSRFile(perfEventSets: EventSets = new EventSets(Seq()))(implicit p: Param
if (usingFPU) if (usingFPU)
read_mapping ++= fp_csrs read_mapping ++= fp_csrs
if (coreParams.haveBasicCounters) {
read_mapping += CSRs.mcycle -> reg_cycle
read_mapping += CSRs.minstret -> reg_instret
for (((e, c), i) <- (reg_hpmevent.padTo(CSR.nHPM, UInt(0)) for (((e, c), i) <- (reg_hpmevent.padTo(CSR.nHPM, UInt(0))
zip reg_hpmcounter.map(x => x: UInt).padTo(CSR.nHPM, UInt(0))) zipWithIndex) { zip reg_hpmcounter.map(x => x: UInt).padTo(CSR.nHPM, UInt(0))) zipWithIndex) {
read_mapping += (i + CSR.firstHPE) -> e // mhpmeventN read_mapping += (i + CSR.firstHPE) -> e // mhpmeventN
@ -383,6 +387,22 @@ class CSRFile(perfEventSets: EventSets = new EventSets(Seq()))(implicit p: Param
} }
} }
if (usingUser) {
read_mapping += CSRs.mcounteren -> reg_mcounteren
read_mapping += CSRs.cycle -> reg_cycle
read_mapping += CSRs.instret -> reg_instret
}
if (xLen == 32) {
read_mapping += CSRs.mcycleh -> (reg_cycle >> 32)
read_mapping += CSRs.minstreth -> (reg_instret >> 32)
if (usingUser) {
read_mapping += CSRs.cycleh -> (reg_cycle >> 32)
read_mapping += CSRs.instreth -> (reg_instret >> 32)
}
}
}
if (usingVM) { if (usingVM) {
val read_sie = reg_mie & reg_mideleg val read_sie = reg_mie & reg_mideleg
val read_sip = read_mip & reg_mideleg val read_sip = read_mip & reg_mideleg
@ -412,21 +432,6 @@ class CSRFile(perfEventSets: EventSets = new EventSets(Seq()))(implicit p: Param
read_mapping += CSRs.medeleg -> reg_medeleg read_mapping += CSRs.medeleg -> reg_medeleg
} }
if (usingUser) {
read_mapping += CSRs.mcounteren -> reg_mcounteren
read_mapping += CSRs.cycle -> reg_cycle
read_mapping += CSRs.instret -> reg_instret
}
if (xLen == 32) {
read_mapping += CSRs.mcycleh -> (reg_cycle >> 32)
read_mapping += CSRs.minstreth -> (reg_instret >> 32)
if (usingUser) {
read_mapping += CSRs.cycleh -> (reg_cycle >> 32)
read_mapping += CSRs.instreth -> (reg_instret >> 32)
}
}
val pmpCfgPerCSR = xLen / new PMPConfig().getWidth val pmpCfgPerCSR = xLen / new PMPConfig().getWidth
def pmpCfgIndex(i: Int) = (xLen / 32) * (i / pmpCfgPerCSR) def pmpCfgIndex(i: Int) = (xLen / 32) * (i / pmpCfgPerCSR)
if (reg_pmp.nonEmpty) { if (reg_pmp.nonEmpty) {
@ -438,13 +443,6 @@ class CSRFile(perfEventSets: EventSets = new EventSets(Seq()))(implicit p: Param
read_mapping += (CSRs.pmpaddr0 + i) -> pmp.addr read_mapping += (CSRs.pmpaddr0 + i) -> pmp.addr
} }
for (i <- 0 until nCustomMrwCsrs) {
val addr = 0xff0 + i
require(addr < (1 << CSR.ADDRSZ))
require(!read_mapping.contains(addr), "custom MRW CSR address " + i + " is already in use")
read_mapping += addr -> io.custom_mrw_csrs(i)
}
val decoded_addr = read_mapping map { case (k, v) => k -> (io.rw.addr === k) } val decoded_addr = read_mapping map { case (k, v) => k -> (io.rw.addr === k) }
val wdata = readModifyWriteCSR(io.rw.cmd, io.rw.rdata, io.rw.wdata) val wdata = readModifyWriteCSR(io.rw.cmd, io.rw.rdata, io.rw.wdata)
@ -511,7 +509,7 @@ class CSRFile(perfEventSets: EventSets = new EventSets(Seq()))(implicit p: Param
assert(PopCount(insn_ret :: insn_call :: insn_break :: io.exception :: Nil) <= 1, "these conditions must be mutually exclusive") assert(PopCount(insn_ret :: insn_call :: insn_break :: io.exception :: Nil) <= 1, "these conditions must be mutually exclusive")
when (insn_wfi && !io.singleStep && !reg_debug) { reg_wfi := true } when (insn_wfi && !io.singleStep && !reg_debug) { reg_wfi := true }
when (pending_interrupts.orR || exception || reg_debugint) { reg_wfi := false } when (pending_interrupts.orR || exception || io.interrupts.debug) { reg_wfi := false }
assert(!reg_wfi || io.retire === UInt(0)) assert(!reg_wfi || io.retire === UInt(0))
when (io.retire(0) || exception) { reg_singleStepped := true } when (io.retire(0) || exception) { reg_singleStepped := true }
@ -611,6 +609,7 @@ class CSRFile(perfEventSets: EventSets = new EventSets(Seq()))(implicit p: Param
when (decoded_addr(CSRs.misa)) { when (decoded_addr(CSRs.misa)) {
val mask = UInt(isaStringToMask(isaMaskString), xLen) val mask = UInt(isaStringToMask(isaMaskString), xLen)
val f = wdata('f' - 'a') val f = wdata('f' - 'a')
if (coreParams.misaWritable)
reg_misa := ~(~wdata | (!f << ('d' - 'a'))) & mask | reg_misa & ~mask reg_misa := ~(~wdata | (!f << ('d' - 'a'))) & mask | reg_misa & ~mask
} }
when (decoded_addr(CSRs.mip)) { when (decoded_addr(CSRs.mip)) {
@ -637,8 +636,10 @@ class CSRFile(perfEventSets: EventSets = new EventSets(Seq()))(implicit p: Param
writeCounter(i + CSR.firstMHPC, c, wdata) writeCounter(i + CSR.firstMHPC, c, wdata)
when (decoded_addr(i + CSR.firstHPE)) { e := perfEventSets.maskEventSelector(wdata) } when (decoded_addr(i + CSR.firstHPE)) { e := perfEventSets.maskEventSelector(wdata) }
} }
if (coreParams.haveBasicCounters) {
writeCounter(CSRs.mcycle, reg_cycle, wdata) writeCounter(CSRs.mcycle, reg_cycle, wdata)
writeCounter(CSRs.minstret, reg_instret, wdata) writeCounter(CSRs.minstret, reg_instret, wdata)
}
if (usingFPU) { if (usingFPU) {
when (decoded_addr(CSRs.fflags)) { reg_fflags := wdata } when (decoded_addr(CSRs.fflags)) { reg_fflags := wdata }
@ -721,12 +722,6 @@ class CSRFile(perfEventSets: EventSets = new EventSets(Seq()))(implicit p: Param
} }
} }
reg_mip.lip := (io.interrupts.lip: Seq[Bool])
reg_mip.mtip := io.interrupts.mtip
reg_mip.msip := io.interrupts.msip
reg_mip.meip := io.interrupts.meip
reg_debugint := io.interrupts.debug
if (!usingVM) { if (!usingVM) {
reg_mideleg := 0 reg_mideleg := 0
reg_medeleg := 0 reg_medeleg := 0

View File

@ -75,7 +75,6 @@ class FrontendModule(outer: Frontend) extends LazyModuleImp(outer)
val icache = outer.icache.module val icache = outer.icache.module
require(fetchWidth*coreInstBytes == outer.icacheParams.fetchBytes) require(fetchWidth*coreInstBytes == outer.icacheParams.fetchBytes)
val fetchBytes = coreInstBytes * fetchWidth
val tlb = Module(new TLB(true, log2Ceil(fetchBytes), nTLBEntries)) val tlb = Module(new TLB(true, log2Ceil(fetchBytes), nTLBEntries))
val fq = withReset(reset || io.cpu.req.valid) { Module(new ShiftQueue(new FrontendResp, 5, flow = true)) } val fq = withReset(reset || io.cpu.req.valid) { Module(new ShiftQueue(new FrontendResp, 5, flow = true)) }

View File

@ -127,7 +127,7 @@ class PMPHomogeneityChecker(pmps: Seq[PMP])(implicit p: Parameters) {
} }
class PMPChecker(lgMaxSize: Int)(implicit p: Parameters) extends CoreModule()(p) class PMPChecker(lgMaxSize: Int)(implicit p: Parameters) extends CoreModule()(p)
with HasRocketCoreParameters { with HasCoreParameters {
val io = new Bundle { val io = new Bundle {
val prv = UInt(INPUT, PRV.SZ) val prv = UInt(INPUT, PRV.SZ)
val pmp = Vec(nPMPs, new PMP).asInput val pmp = Vec(nPMPs, new PMP).asInput

View File

@ -24,7 +24,7 @@ class PTWResp(implicit p: Parameters) extends CoreBundle()(p) {
} }
class TLBPTWIO(implicit p: Parameters) extends CoreBundle()(p) class TLBPTWIO(implicit p: Parameters) extends CoreBundle()(p)
with HasRocketCoreParameters { with HasCoreParameters {
val req = Decoupled(new PTWReq) val req = Decoupled(new PTWReq)
val resp = Valid(new PTWResp).flip val resp = Valid(new PTWResp).flip
val ptbr = new PTBR().asInput val ptbr = new PTBR().asInput
@ -37,7 +37,7 @@ class PTWPerfEvents extends Bundle {
} }
class DatapathPTWIO(implicit p: Parameters) extends CoreBundle()(p) class DatapathPTWIO(implicit p: Parameters) extends CoreBundle()(p)
with HasRocketCoreParameters { with HasCoreParameters {
val ptbr = new PTBR().asInput val ptbr = new PTBR().asInput
val sfence = Valid(new SFenceReq).flip val sfence = Valid(new SFenceReq).flip
val status = new MStatus().asInput val status = new MStatus().asInput

View File

@ -23,7 +23,8 @@ case class RocketCoreParams(
nBreakpoints: Int = 1, nBreakpoints: Int = 1,
nPMPs: Int = 8, nPMPs: Int = 8,
nPerfCounters: Int = 0, nPerfCounters: Int = 0,
nCustomMRWCSRs: Int = 0, haveBasicCounters: Boolean = true,
misaWritable: Boolean = true,
nL2TLBEntries: Int = 0, nL2TLBEntries: Int = 0,
mtvecInit: Option[BigInt] = Some(BigInt(0)), mtvecInit: Option[BigInt] = Some(BigInt(0)),
mtvecWritable: Boolean = true, mtvecWritable: Boolean = true,
@ -46,12 +47,6 @@ trait HasRocketCoreParameters extends HasCoreParameters {
val fastLoadWord = rocketParams.fastLoadWord val fastLoadWord = rocketParams.fastLoadWord
val fastLoadByte = rocketParams.fastLoadByte val fastLoadByte = rocketParams.fastLoadByte
val nBreakpoints = rocketParams.nBreakpoints
val nPMPs = rocketParams.nPMPs
val nPerfCounters = rocketParams.nPerfCounters
val nCustomMrwCsrs = rocketParams.nCustomMRWCSRs
val mtvecInit = rocketParams.mtvecInit
val mtvecWritable = rocketParams.mtvecWritable
val mulDivParams = rocketParams.mulDiv.getOrElse(MulDivParams()) // TODO ask andrew about this val mulDivParams = rocketParams.mulDiv.getOrElse(MulDivParams()) // TODO ask andrew about this

View File

@ -25,7 +25,14 @@ trait CoreParams {
val retireWidth: Int val retireWidth: Int
val instBits: Int val instBits: Int
val nLocalInterrupts: Int val nLocalInterrupts: Int
val nPMPs: Int
val nBreakpoints: Int
val nPerfCounters: Int
val haveBasicCounters: Boolean
val misaWritable: Boolean
val nL2TLBEntries: Int val nL2TLBEntries: Int
val mtvecInit: Option[BigInt]
val mtvecWritable: Boolean
val jumpInFrontend: Boolean val jumpInFrontend: Boolean
val tileControlAddr: Option[BigInt] val tileControlAddr: Option[BigInt]
@ -47,12 +54,19 @@ trait HasCoreParameters extends HasTileParameters {
val fetchWidth = coreParams.fetchWidth val fetchWidth = coreParams.fetchWidth
val decodeWidth = coreParams.decodeWidth val decodeWidth = coreParams.decodeWidth
val fetchBytes = coreParams.fetchBytes
val coreInstBits = coreParams.instBits val coreInstBits = coreParams.instBits
val coreInstBytes = coreInstBits/8 val coreInstBytes = coreInstBits/8
val coreDataBits = xLen max fLen val coreDataBits = xLen max fLen
val coreDataBytes = coreDataBits/8 val coreDataBytes = coreDataBits/8
val coreMaxAddrBits = paddrBits max vaddrBitsExtended val coreMaxAddrBits = paddrBits max vaddrBitsExtended
val nBreakpoints = coreParams.nBreakpoints
val nPMPs = coreParams.nPMPs
val nPerfCounters = coreParams.nPerfCounters
val mtvecInit = coreParams.mtvecInit
val mtvecWritable = coreParams.mtvecWritable
val coreDCacheReqTagBits = 6 val coreDCacheReqTagBits = 6
val dcacheReqTagBits = coreDCacheReqTagBits + log2Ceil(dcacheArbPorts) val dcacheReqTagBits = coreDCacheReqTagBits + log2Ceil(dcacheArbPorts)