Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
55 commits
Select commit Hold shift + click to select a range
6aa3592
feat: add some inst
Chrisqcwx Mar 19, 2023
6a5a383
feat: add branch inst
Chrisqcwx Mar 20, 2023
1562843
feat: add branch inst
Chrisqcwx Mar 20, 2023
53284e8
Merge branch 'main' of github.com:Invalid-Syntax-NSCSCC/invalid-cpu
Chrisqcwx Mar 20, 2023
20b2f67
Merge branch 'main' of github.com:Invalid-Syntax-NSCSCC/invalid-cpu i…
Chrisqcwx Mar 20, 2023
651dd92
feat: add branch inst
Chrisqcwx Mar 20, 2023
87b6016
fix: fix some bug in MulStage
Chrisqcwx Mar 20, 2023
4099b34
feat: add load store inst
Chrisqcwx Mar 20, 2023
b9592b2
feat: add load and store inst
Chrisqcwx Mar 21, 2023
f175e9e
Merge branch 'dev-yhy'
Chrisqcwx Mar 21, 2023
1cab7e2
fix: deal conflict
Chrisqcwx Mar 21, 2023
bae2228
fix: fix some bug in ExeStage
Chrisqcwx Mar 21, 2023
d240163
fix: add decoder fallback
Chrisqcwx Mar 21, 2023
dbfe974
delete temp issueStage
Chrisqcwx Mar 21, 2023
a1ab1a1
refactor: add insts in SimpleCpuSpec
Chrisqcwx Mar 22, 2023
aabdf2d
refactor: comments
Mar 22, 2023
7c3452c
fix: make bullshit in `IssueStage` smell better
Mar 22, 2023
8db4f3b
fix: when you are free to go, even you are still in blocking state, y…
Mar 22, 2023
9ce6d48
test some inst
Chrisqcwx Mar 22, 2023
a8d83f2
Merge branch 'dev-yhy' of github.com:Invalid-Syntax-NSCSCC/invalid-cp…
Chrisqcwx Mar 22, 2023
0f3eba8
fix: now it's not a mess in `IssueStage`
Mar 23, 2023
d7ea58c
Merge branch 'dev-yhy' of github.com:Invalid-Syntax-NSCSCC/invalid-cp…
Chrisqcwx Mar 23, 2023
9bb53df
refactor: refactor exeStage with state machine
Chrisqcwx Mar 23, 2023
ad419bf
refactor: alu
Chrisqcwx Mar 23, 2023
72a6c6a
refactor: reformat
Chrisqcwx Mar 24, 2023
1dc7725
feat: avoid recalculating mul and div in alu when stall
Chrisqcwx Mar 25, 2023
035f1c3
refactor: reformat
Chrisqcwx Mar 25, 2023
6a09062
deal with conflicts
Chrisqcwx Mar 25, 2023
02fde3c
deal with conflicts
Chrisqcwx Mar 25, 2023
31e519c
feat: add some inst
Chrisqcwx Mar 25, 2023
0d52bcd
refactor: reformat
Chrisqcwx Mar 25, 2023
f8f6b2b
feat: add mem stage
Chrisqcwx Mar 26, 2023
f77c9ee
refactor: rename MemLoadStoreNdPort -> MemLoadStoreInfoNdPort
Chrisqcwx Mar 26, 2023
2f84aaf
deal with conflicts
Chrisqcwx Mar 26, 2023
ddbca6c
Merge branch 'main' into dev-yhy
rewired-gh Mar 27, 2023
6b2c83c
refactor: modify some comment
Chrisqcwx Mar 27, 2023
0d3d633
Merge branch 'dev-yhy' of github.com:Invalid-Syntax-NSCSCC/invalid-cp…
Chrisqcwx Mar 27, 2023
1971768
deal with conflicts
Chrisqcwx Mar 27, 2023
97514d6
Merge branch 'main' of github.com:Invalid-Syntax-NSCSCC/invalid-cpu i…
Chrisqcwx Mar 27, 2023
e6cb6d4
refactor: refactor Mul module with booth algorithm and wallance tree.
Chrisqcwx Mar 27, 2023
03ddec4
fix: memLoadStoreInfoPort lack 1 cycle delay; feat: add CsrRegs
Chrisqcwx Mar 28, 2023
65881d7
refactor: reformat
Chrisqcwx Mar 28, 2023
dab47b2
fix: fix some bugs
Chrisqcwx Mar 28, 2023
3803d9d
feat: add some Exception; issue: add some TODO
Chrisqcwx Mar 28, 2023
e114584
fix: fix uninitialize error in issueStage
Chrisqcwx Mar 29, 2023
66365e1
feat: add some exceptions
Chrisqcwx Mar 29, 2023
7c26830
Merge branch 'main' of github.com:Invalid-Syntax-NSCSCC/invalid-cpu i…
Chrisqcwx Mar 29, 2023
1d06144
refactor: rename WbDebugPort --> InstInfoPort
Chrisqcwx Mar 29, 2023
3ab4472
feat: add cu's control of gprWrite
Chrisqcwx Mar 29, 2023
7726a4f
fix: delete divisor is zero exception (according to the instruction m…
Chrisqcwx Mar 30, 2023
f5b8001
refactor: add bundle-UInt support in csr
Chrisqcwx Mar 31, 2023
fa3c315
fix: deal conflicts
Chrisqcwx Mar 31, 2023
0604065
feat: add many csr regs
Chrisqcwx Mar 31, 2023
1b68755
feat: add clear and flush output in Cu
Chrisqcwx Mar 31, 2023
3b4fda5
feat: add clear and flush in pipeline
Chrisqcwx Mar 31, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions src/src/CoreCpuTop.scala
Original file line number Diff line number Diff line change
Expand Up @@ -239,14 +239,14 @@ class CoreCpuTop extends Module {
// Write-back stage
wbStage.io.gprWriteInfoPort := memStage.io.gprWritePassThroughPort.out
wbStage.io.instInfoPassThroughPort.in := memStage.io.instInfoPassThroughPort.out
regFile.io.writePort := cu.io.gprWritePassThroughPort.out
regFile.io.writePort := cu.io.gprWritePassThroughPorts.out(0)
scoreboard.io.freePorts := wbStage.io.freePorts

// Ctrl unit
cu.io.instInfoPort := wbStage.io.instInfoPassThroughPort.out
cu.io.exeStallRequest := exeStage.io.stallRequest
cu.io.memStallRequest := memStage.io.stallRequest
cu.io.gprWritePassThroughPort.in := wbStage.io.gprWritePort
cu.io.instInfoPorts(0) := wbStage.io.instInfoPassThroughPort.out
cu.io.exeStallRequest := exeStage.io.stallRequest
cu.io.memStallRequest := memStage.io.stallRequest
cu.io.gprWritePassThroughPorts.in(0) := wbStage.io.gprWritePort

// Csr
csr.io.writePorts.zip(cu.io.csrWritePorts).foreach {
Expand Down
212 changes: 206 additions & 6 deletions src/src/pipeline/ctrl/Csr.scala
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,127 @@ import chisel3.experimental.BundleLiterals.AddBundleLiteralConstructor
import spec._
import pipeline.ctrl.bundles.PipelineControlNDPort
import spec.PipelineStageIndex
import pipeline.ctrl.bundles.CsrWriteNdPort
import pipeline.ctrl.bundles._
import pipeline.ctrl.bundles.EentryBundle
import pipeline.ctrl.bundles.TlbehiBundle

class Csr(writeNum: Int = Param.csrRegsWriteNum) extends Module {
val io = IO(new Bundle {
val writePorts = Input(Vec(writeNum, new CsrWriteNdPort))
val csrValues = Output(Vec(Count.csrReg, UInt(Width.Reg.data)))
})

// Util: view UInt as Bundle
class BundlePassPort[T <: Bundle](port: T) extends Bundle {
val in = Wire(port)
val out = Wire(port)
}

def viewUInt[T <: Bundle](u: UInt, bun: T): BundlePassPort[T] = {
val passPort = new BundlePassPort(bun)
u := passPort.in.asUInt
passPort.out := u.asTypeOf(bun)
passPort
}

val csrRegs = RegInit(VecInit(Seq.fill(Count.csrReg)(zeroWord)))

io.writePorts.foreach { writePort =>
when(writePort.en) {
csrRegs(writePort.addr) := writePort.data
// 保留域
switch(writePort.addr) {
is(CsrRegs.Index.crmd) {
csrRegs(writePort.addr) := Cat(0.U(23.W), writePort.data(8, 0))
}
is(CsrRegs.Index.prmd) {
csrRegs(writePort.addr) := Cat(0.U(29.W), writePort.data(2, 0))
}
is(CsrRegs.Index.euen) {
csrRegs(writePort.addr) := Cat(0.U(31.W), writePort.data(0))
}
is(CsrRegs.Index.ecfg) {
csrRegs(writePort.addr) := Cat(0.U(19.W), writePort.data(12, 0))
}
is(CsrRegs.Index.estat) {
csrRegs(writePort.addr) := Cat(false.B, writePort.data(30, 16), 0.U(3.W), writePort.data(12, 0))
}
is(
CsrRegs.Index.era,
CsrRegs.Index.badv,
CsrRegs.Index.save0,
CsrRegs.Index.save1,
CsrRegs.Index.save2,
CsrRegs.Index.save3,
CsrRegs.Index.tid
) {
csrRegs(writePort.addr) := writePort.data
}
is(CsrRegs.Index.eentry) {
csrRegs(writePort.addr) := Cat(writePort.data(31, 6), 0.U(6.W))
}
is(CsrRegs.Index.cpuid) {
csrRegs(writePort.addr) := Cat(0.U(23.W), writePort.data(8, 0))
}
is(CsrRegs.Index.llbctl) {
csrRegs(writePort.addr) := Cat(0.U(29.W), writePort.data(2, 0))
}
is(CsrRegs.Index.tlbidx) {
csrRegs(writePort.addr) := Cat(
writePort.data(31),
false.B,
writePort.data(29, 24),
0.U((24 - CsrRegs.Tlbidx.Width.index).W),
writePort.data(CsrRegs.Tlbidx.Width.index - 1, 0)
)
}
is(CsrRegs.Index.tlbehi) {
csrRegs(writePort.addr) := Cat(writePort.data(31, 13), 0.U(13.W))
}
is(CsrRegs.Index.tlbelo0, CsrRegs.Index.tlbelo1) {
csrRegs(writePort.addr) := Cat(
writePort.data(31, 8),
false.B,
writePort.data(6, 0)
)
}
is(CsrRegs.Index.asid) {
csrRegs(writePort.addr) := Cat(
0.U(8.W),
writePort.data(23, 16),
0.U(6.W),
writePort.data(9, 0)
)
}
is(CsrRegs.Index.pgdl, CsrRegs.Index.pgdh, CsrRegs.Index.pgd) {
csrRegs(writePort.addr) := Cat(writePort.data(31, 12), 0.U(12.W))
}
is(CsrRegs.Index.tlbrentry) {
csrRegs(writePort.addr) := Cat(writePort.data(31, 6), 0.U(6.W))
}
is(CsrRegs.Index.dmw0, CsrRegs.Index.dmw1) {
csrRegs(writePort.addr) := Cat(
writePort.data(31, 29),
false.B,
writePort.data(27, 25),
0.U(19.W),
writePort.data(5, 3),
0.U(2.W),
writePort.data(0)
)
}
is(CsrRegs.Index.tcfg, CsrRegs.Index.tval) {
csrRegs(writePort.addr) := Cat(
0.U((32 - CsrRegs.TimeVal.Width.timeVal).W),
writePort.data(CsrRegs.TimeVal.Width.timeVal - 1, 0)
)
}
is(CsrRegs.Index.ticlr) {
csrRegs(writePort.addr) := Cat(
0.U(31.W),
writePort.data(0)
)
}
}
}
}
Expand All @@ -33,12 +136,109 @@ class Csr(writeNum: Int = Param.csrRegsWriteNum) extends Module {
output := reg
}

// CRMD 当前模式信息

val crmd = viewUInt(csrRegs(CsrRegs.Index.crmd), new CrmdBundle)
crmd.in := CrmdBundle.default

// PRMD 例外前模式信息
val prmd = viewUInt(csrRegs(CsrRegs.Index.prmd), new PrmdBundle)
prmd.in := PrmdBundle.default

// EUEN扩展部件使能
val euen = viewUInt(csrRegs(CsrRegs.Index.euen), new EuenBundle)
euen.in := EuenBundle.default

// ECFG 例外控制
val ecfg = viewUInt(csrRegs(CsrRegs.Index.ecfg), new EcfgBundle)
ecfg.in := EcfgBundle.default

// ESTAT
val estatRegValue = WireDefault(csrRegs(CsrRegs.Index.estat))
val estat = new Bundle {
val is = estatRegValue(12, 0)
val ecode = estatRegValue(21, 16)
val esubcode = estatRegValue(30, 22)
val estat = viewUInt(csrRegs(CsrRegs.Index.estat), new EstatBundle)
estat.in := EstatBundle.default

// ERA 例外返回地址
val era = viewUInt(csrRegs(CsrRegs.Index.era), new EraBundle)
era.in := EraBundle.default

// BADV 出错虚地址
val badv = viewUInt(csrRegs(CsrRegs.Index.badv), new BadvBundle)
badv.in := BadvBundle.default

// EENTRY 例外入口地址
val eentry = viewUInt(csrRegs(CsrRegs.Index.eentry), new EentryBundle)
eentry.in := EentryBundle.default

// CPUID 处理器编号
val cpuid = viewUInt(csrRegs(CsrRegs.Index.cpuid), new CpuidBundle)
cpuid.in := CpuidBundle.default

// SAVE0-3 数据保存
val saves = VecInit(CsrRegs.Index.save0, CsrRegs.Index.save1, CsrRegs.Index.save2, CsrRegs.Index.save3).map { idx =>
viewUInt(csrRegs(idx), new CsrSaveBundle)
}
saves.foreach { save => save.in := CsrSaveBundle.default }

// LLBCTL LLBit控制
val llbctl = viewUInt(csrRegs(CsrRegs.Index.llbctl), new LlbctlBundle)
llbctl.in := LlbctlBundle.default

// TLBIDX TLB索引
val tlbidx = viewUInt(csrRegs(CsrRegs.Index.tlbidx), new TlbidxBundle)
tlbidx.in := TlbidxBundle.default

// TLBEHI TLB表项高位
val tlbehi = viewUInt(csrRegs(CsrRegs.Index.tlbehi), new TlbehiBundle)
tlbehi.in := TlbehiBundle.default

// TLBELO 0-1 TLB表项低位
val tlbelo0 = viewUInt(csrRegs(CsrRegs.Index.tlbelo0), new TlbeloBundle)
tlbelo0.in := TlbeloBundle.default

val tlbelo1 = viewUInt(csrRegs(CsrRegs.Index.tlbelo1), new TlbeloBundle)
tlbelo1.in := TlbeloBundle.default

// ASID 地址空间标识符
val asid = viewUInt(csrRegs(CsrRegs.Index.asid), new AsidBundle)
asid.in := AsidBundle.default

// PGDL 低半地址空间全局目录基址
val pgdl = viewUInt(csrRegs(CsrRegs.Index.pgdl), new PgdlBundle)
pgdl.in := PgdlBundle.default

// PGDH 高半地址空间全局目录基址
val pgdh = viewUInt(csrRegs(CsrRegs.Index.pgdh), new PgdhBundle)
pgdh.in := PgdhBundle.default

// PGD 全局地址空间全局目录基址
val pgd = viewUInt(csrRegs(CsrRegs.Index.pgd), new PgdBundle)
pgd.in := PgdBundle.default

// TLBRENTRY TLB重填例外入口地址
val tlbrentry = viewUInt(csrRegs(CsrRegs.Index.tlbrentry), new TlbrentryBundle)
tlbrentry.in := TlbrentryBundle.default

// DMW 0-1 直接映射配置窗口
val dmw0 = viewUInt(csrRegs(CsrRegs.Index.dmw0), new DmwBundle)
dmw0.in := DmwBundle.default

val dmw1 = viewUInt(csrRegs(CsrRegs.Index.dmw1), new DmwBundle)
dmw1.in := DmwBundle.default

// TID 定时器编号
val tid = viewUInt(csrRegs(CsrRegs.Index.tid), new TidBundle)
tid.in := TidBundle.default

// TCFG 定时器配置
val tcfg = viewUInt(csrRegs(CsrRegs.Index.tcfg), new TcfgBundle)
tcfg.in := TcfgBundle.default

// TVAL 定时器数值
val tval = viewUInt(csrRegs(CsrRegs.Index.tval), new TvalBundle)
tval.in := TvalBundle.default

// TICLR 定时器中断清除
val ticlr = viewUInt(csrRegs(CsrRegs.Index.ticlr), new TiclrBundle)
ticlr.in := TiclrBundle.default

}
57 changes: 43 additions & 14 deletions src/src/pipeline/ctrl/Cu.scala
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,15 @@ import pipeline.ctrl.bundles.CsrWriteNdPort
// TODO: Add stall to frontend ?
// TODO: Add flush to stages
// TODO: Add deal exceptions
class Cu(ctrlControlNum: Int = Param.ctrlControlNum, writeNum: Int = Param.csrRegsWriteNum) extends Module {
class Cu(
ctrlControlNum: Int = Param.ctrlControlNum,
writeNum: Int = Param.csrRegsWriteNum,
dispatchNum: Int = Param.dispatchInstNum)
extends Module {
val io = IO(new Bundle {
// `WbStage` -> `Cu`
val gprWritePassThroughPort = new PassThroughPort(new RfWriteNdPort)
val instInfoPort = Input(new InstInfoNdPort)
val gprWritePassThroughPorts = new PassThroughPort(Vec(dispatchNum, new RfWriteNdPort))
val instInfoPorts = Input(Vec(dispatchNum, new InstInfoNdPort))
// `Cu` -> `Csr`
val csrWritePorts = Output(Vec(writeNum, new CsrWriteNdPort))
// `ExeStage` -> `Cu`
Expand All @@ -29,32 +33,57 @@ class Cu(ctrlControlNum: Int = Param.ctrlControlNum, writeNum: Int = Param.csrRe
val pipelineControlPorts = Output(Vec(ctrlControlNum, new PipelineControlNDPort))
})

// TODO: Finish correct connection
io.csrWritePorts := DontCare

/** Stall
/** Stall 暂停流水线前面部分
*/

io.pipelineControlPorts.foreach(_ := PipelineControlNDPort.default)
// `ExeStage` --stall--> `IssueStage`, `RegReadStage` (DONT STALL ITSELF)
Seq(PipelineStageIndex.issueStage, PipelineStageIndex.regReadStage)
// `ExeStage` --stall--> `IssueStage`, `RegReadStage`, `ExeStage` (STALL ITSELF)
Seq(PipelineStageIndex.issueStage, PipelineStageIndex.regReadStage, PipelineStageIndex.exeStage)
.map(io.pipelineControlPorts(_))
.foreach(_.stall := io.exeStallRequest)
// `MemStage` --stall--> `IssueStage`, `RegReadStage`, `ExeStage` (DONT STALL ITSELF)
Seq(PipelineStageIndex.issueStage, PipelineStageIndex.regReadStage, PipelineStageIndex.exeStage)
// `MemStage` --stall--> `IssueStage`, `RegReadStage`, `ExeStage`, `MemStage` (STALL ITSELF)
Seq(
PipelineStageIndex.issueStage,
PipelineStageIndex.regReadStage,
PipelineStageIndex.exeStage,
PipelineStageIndex.memStage
)
.map(io.pipelineControlPorts(_))
.foreach(_.stall := io.memStallRequest)

/** clear
*
* Assume A -> B, A is stall but B is not stall. Give A a clear signal to clear its output
*/

Seq(
PipelineStageIndex.issueStage,
PipelineStageIndex.regReadStage,
PipelineStageIndex.exeStage,
PipelineStageIndex.memStage
).map(io.pipelineControlPorts(_)).reduce { (prev, next) =>
prev.clear := prev.stall && !next.stall
next
}

/** Exception
*/
val hasException = WireDefault(io.instInfoPort.exceptionRecords.reduce(_ || _))
val hasException = WireDefault(io.instInfoPorts.map(_.exceptionRecords.reduce(_ || _)).reduce(_ || _))

/** Write Regfile
*/
// temp
io.gprWritePassThroughPort.out := Mux(
io.gprWritePassThroughPorts.out(0) := Mux(
hasException,
io.gprWritePassThroughPort.in,
io.gprWritePassThroughPorts.in(0),
RfWriteNdPort.default
)

io.csrWritePorts.foreach { port => port := CsrWriteNdPort.default }

/** flush
*/

val flush = WireDefault(hasException)
io.pipelineControlPorts.foreach(_.flush := flush)
}
16 changes: 16 additions & 0 deletions src/src/pipeline/ctrl/bundles/AsidBundle.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package pipeline.ctrl.bundles

import chisel3._
import chisel3.experimental.BundleLiterals.AddBundleLiteralConstructor
import spec._

class AsidBundle extends Bundle {
val zero1 = UInt(8.W)
val asidbits = UInt(8.W)
val zero2 = UInt(6.W)
val asid = UInt(10.W)
}

object AsidBundle {
val default = 0.U.asTypeOf(new AsidBundle)
}
13 changes: 13 additions & 0 deletions src/src/pipeline/ctrl/bundles/BadvBundle.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package pipeline.ctrl.bundles

import chisel3._
import chisel3.experimental.BundleLiterals.AddBundleLiteralConstructor
import spec._

class BadvBundle extends Bundle {
val vaddr = UInt(Width.Reg.data)
}

object BadvBundle {
val default = 0.U.asTypeOf(new BadvBundle)
}
14 changes: 14 additions & 0 deletions src/src/pipeline/ctrl/bundles/CpuidBundle.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package pipeline.ctrl.bundles

import chisel3._
import chisel3.experimental.BundleLiterals.AddBundleLiteralConstructor
import spec._

class CpuidBundle extends Bundle {
val zero = UInt(23.W)
val coreId = UInt(9.W)
}

object CpuidBundle {
val default = 0.U.asTypeOf(new CpuidBundle)
}
Loading