Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rocket cosim framework #3271

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from 3 commits
Commits
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
514 changes: 514 additions & 0 deletions build.sc

Large diffs are not rendered by default.

5 changes: 5 additions & 0 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@
verilator cmake ninja
python3 python3Packages.bootstrapped-pip
pkgsCross.riscv64-embedded.buildPackages.gcc

libargs glog fmt zlib
gnused coreutils gnugrep which
parallel protobuf antlr4 numactl
Comment on lines +26 to +28
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Only need to add necessary dependencies.


circt

spike riscvTests
Expand Down
49 changes: 48 additions & 1 deletion overlay.nix
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
final: prev: {
final: prev:
let
riscvTests = final.pkgsCross.riscv64-embedded.stdenv.mkDerivation rec {
pname = "riscv-tests";
version = "55bbcc8c06637a31cc01970881ba8072838a9121";
Expand All @@ -17,4 +18,50 @@ final: prev: {
];
buildPhase = "make RISCV_PREFIX=riscv64-none-elf-";
};

libspike = let
version = "1.1.0";
pname = "libspike";
cmakeConfig = ''
add_library(libspike STATIC IMPORTED GLOBAL)
set_target_properties(libspike PROPERTIES
IMPORTED_LOCATION "${placeholder "out"}/lib/libriscv.so")
target_include_directories(libspike INTERFACE
"${placeholder "out"}/include"
"${placeholder "out"}/include/riscv"
"${placeholder "out"}/include/fesvr"
"${placeholder "out"}/include/softfloat"
)
'';
in
final.stdenv.mkDerivation {
inherit version pname cmakeConfig;
enableParallelBuilding = true;
nativeBuildInputs = [ final.dtc ];
src = final.fetchFromGitHub {
owner = "riscv";
repo = "riscv-isa-sim";
rev = "ab3225a3ff687fda8b4180f9e4e0949a400d1247";
sha256 = "sha256-2cC2goTmxWnkTm3Tq08R8YkkuI2Fj8fRvpEPVZ5JvUI=";
};
configureFlags = [
"--enable-commitlog"
];
installPhase = ''
runHook preInstall
mkdir -p $out/include/{riscv,fesvr,softfloat} $out/lib $out/lib/cmake/libspike
cp riscv/*.h $out/include/riscv
cp fesvr/*.h $out/include/fesvr
cp softfloat/*.h $out/include/softfloat
cp config.h $out/include
cp *.so $out/lib
echo "$cmakeConfig" > $out/lib/cmake/libspike/libspike-config.cmake
runHook postInstall
'';
};
in
{
inherit libspike riscvTests;


}
27 changes: 2 additions & 25 deletions src/main/scala/tile/Interrupts.scala
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
// See LICENSE.SiFive for license details.

package freechips.rocketchip.tile
package tile
midnighter95 marked this conversation as resolved.
Show resolved Hide resolved

import Chisel._

import org.chipsalliance.cde.config.Parameters
import freechips.rocketchip.config.Parameters
midnighter95 marked this conversation as resolved.
Show resolved Hide resolved
import freechips.rocketchip.diplomacy._
import freechips.rocketchip.interrupts._
import freechips.rocketchip.util._
Expand Down Expand Up @@ -32,29 +32,6 @@ trait SinksExternalInterrupts { this: BaseTile =>
protected val intSinkNode = IntSinkNode(IntSinkPortSimple())
intSinkNode := intXbar.intnode

def cpuDevice: Device
val intcDevice = new DeviceSnippet {
override def parent = Some(cpuDevice)
def describe(): Description = {
Description("interrupt-controller", Map(
"compatible" -> "riscv,cpu-intc".asProperty,
"interrupt-controller" -> Nil,
"#interrupt-cells" -> 1.asProperty))
}
}

ResourceBinding {
intSinkNode.edges.in.flatMap(_.source.sources).map { case s =>
for (i <- s.range.start until s.range.end) {
csrIntMap.lift(i).foreach { j =>
s.resources.foreach { r =>
r.bind(intcDevice, ResourceInt(j))
}
}
}
}
}
midnighter95 marked this conversation as resolved.
Show resolved Hide resolved

// TODO: the order of the following two functions must match, and
// also match the order which things are connected to the
// per-tile crossbar in subsystem.HasTiles.connectInterrupts
Expand Down
45 changes: 16 additions & 29 deletions src/main/scala/tile/RocketTile.scala
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
// See LICENSE.SiFive for license details.
// See LICENSE.Berkeley for license details.

package freechips.rocketchip.tile
package tile
midnighter95 marked this conversation as resolved.
Show resolved Hide resolved

import Chisel._
import org.chipsalliance.cde.config._
import freechips.rocketchip.config._
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

don't touch

import freechips.rocketchip.devices.tilelink._
import freechips.rocketchip.diplomacy._
import freechips.rocketchip.interrupts._
Expand Down Expand Up @@ -36,11 +36,11 @@ case class RocketTileParams(
}

class RocketTile private(
val rocketParams: RocketTileParams,
crossing: ClockCrossingType,
lookup: LookupByHartIdImpl,
q: Parameters)
extends BaseTile(rocketParams, crossing, lookup, q)
val rocketParams: RocketTileParams,
crossing: ClockCrossingType,
lookup: LookupByHartIdImpl,
q: Parameters)
extends BaseTile(rocketParams, crossing, lookup, q)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

don't touch

with SinksExternalInterrupts
with SourcesExternalNotifications
with HasLazyRoCC // implies CanHaveSharedFPU with CanHavePTW with HasHellaCache
Expand Down Expand Up @@ -87,20 +87,7 @@ class RocketTile private(
val itimProperty = frontend.icache.itimProperty.toSeq.flatMap(p => Map("sifive,itim" -> p))

val beuProperty = bus_error_unit.map(d => Map(
"sifive,buserror" -> d.device.asProperty)).getOrElse(Nil)

val cpuDevice: SimpleDevice = new SimpleDevice("cpu", Seq("sifive,rocket0", "riscv")) {
override def parent = Some(ResourceAnchors.cpus)
override def describe(resources: ResourceBindings): Description = {
val Description(name, mapping) = super.describe(resources)
Description(name, mapping ++ cpuProperties ++ nextLevelCacheProperty
++ tileProperties ++ dtimProperty ++ itimProperty ++ beuProperty)
}
}

ResourceBinding {
Resource(cpuDevice, "reg").bind(ResourceAddress(staticIdForMetadataUseOnly))
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

don't touch

"sifive,buserror" -> d.device.asProperty)).getOrElse(Nil)

override lazy val module = new RocketTileModuleImp(this)

Expand All @@ -120,9 +107,9 @@ class RocketTile private(
}

class RocketTileModuleImp(outer: RocketTile) extends BaseTileModuleImp(outer)
with HasFpuOpt
with HasLazyRoCCModule
with HasICacheFrontendModule {
with HasFpuOpt
with HasLazyRoCCModule
with HasICacheFrontendModule {
Annotated.params(this, outer.rocketParams)

val core = Module(new Rocket(outer)(outer.p))
Expand All @@ -133,9 +120,9 @@ class RocketTileModuleImp(outer: RocketTile) extends BaseTileModuleImp(outer)
// Report when the tile has ceased to retire instructions; for now the only cause is clock gating
outer.reportCease(outer.rocketParams.core.clockGate.option(
!outer.dcache.module.io.cpu.clock_enabled &&
!outer.frontend.module.io.cpu.clock_enabled &&
!ptw.io.dpath.clock_enabled &&
core.io.cease))
!outer.frontend.module.io.cpu.clock_enabled &&
!ptw.io.dpath.clock_enabled &&
core.io.cease))

outer.reportWFI(Some(core.io.wfi))

Expand Down Expand Up @@ -182,8 +169,8 @@ class RocketTileModuleImp(outer: RocketTile) extends BaseTileModuleImp(outer)
require(h == c, s"port list size was $h, core expected $c")
require(h == o, s"port list size was $h, outer counted $o")
// TODO figure out how to move the below into their respective mix-ins
dcacheArb.io.requestor <> dcachePorts.toSeq
ptw.io.requestor <> ptwPorts.toSeq
dcacheArb.io.requestor <> dcachePorts
ptw.io.requestor <> ptwPorts
}

trait HasFpuOpt { this: RocketTileModuleImp =>
Expand Down
9 changes: 9 additions & 0 deletions tests/cases/entrance/entrance.S
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
.global _start
_start:
auipc t1, 0x0
addi a1, t1, 32
csrr a0, mhartid
lui t0, 0x80000
slli t0,t0,32
srli t0,t0,32
jr t0
19 changes: 19 additions & 0 deletions tests/cases/smoketest/smoke.S
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
.global _start
_start:
add t0,t0,x0
addi t0, x0, 0x1
addi t1, x0, 0x0
addi t3, x0, 0xa
loop:
add t1, t1, t0
add t0, t0, 0x1
add t3, t3, -1
bne t3, x0, loop
sd t1, 0x10(x0)
ld t2, 0x10(x0)
addi x20, x0, 0x1
addi x21, x0, 0x1
addi x22, x0, 0x1
addi x23, x0, 0x1
addi x24, x0, 0x1
addi x25, x0, 0x1
97 changes: 97 additions & 0 deletions tests/cosim/elaborate/src/DUT.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
package cosim.elabotate

import chisel3._
import freechips.rocketchip.diplomacy.{AddressSet, BundleBridgeSource, InModuleBody, LazyModule, RegionType, SimpleLazyModule, TransferSizes}
import freechips.rocketchip.interrupts.{IntSinkNode, IntSinkPortSimple, IntSourceNode, IntSourcePortSimple}
import freechips.rocketchip.subsystem._
import freechips.rocketchip.tilelink.{TLManagerNode, TLSlaveParameters, TLSlavePortParameters}
import org.chipsalliance.cde.config.Parameters
import freechips.rocketchip.tile.{NMI, PriorityMuxHartIdFromSeq, RocketTile}

import org.chipsalliance.cde.config.{Config, Field}

class DUT(p: Parameters) extends Module {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can directly use BaseSubsystem with InstantiatesTiles to construct a minimize version of LazyModule

implicit val implicitP = p
val tileParams = p(RocketTileParamsKey)
val ldut = LazyModule(new SimpleLazyModule {
implicit val implicitP = p
val rocketTile = LazyModule(new RocketTile(tileParams, RocketCrossingParams(), PriorityMuxHartIdFromSeq(Seq(tileParams))))
val masterNode = TLManagerNode(Seq(TLSlavePortParameters.v1(
Seq(TLSlaveParameters.v1(
address = List(AddressSet(0x0, 0xffffffffL)),
regionType = RegionType.UNCACHED,
executable = true,
supportsGet = TransferSizes(1, 64),
supportsAcquireT = TransferSizes(1, 64),
supportsAcquireB = TransferSizes(1, 64),
supportsPutPartial = TransferSizes(1, 64),
supportsPutFull = TransferSizes(1, 64),
supportsLogical = TransferSizes(1, 64),
supportsArithmetic = TransferSizes(1, 64),
fifoId = Some(0))),
beatBytes = 8,
endSinkId = 4,
minLatency = 1
)))
masterNode :=* rocketTile.masterNode
val memory = InModuleBody {
masterNode.makeIOs()
}

val intNode = IntSourceNode(IntSourcePortSimple())
rocketTile.intInwardNode :=* intNode
val intIn = InModuleBody {
intNode.makeIOs()
}

val haltNode = IntSinkNode(IntSinkPortSimple())
haltNode :=* rocketTile.haltNode
val haltOut = InModuleBody {
haltNode.makeIOs()
}

val ceaseNode = IntSinkNode(IntSinkPortSimple())
ceaseNode :=* rocketTile.ceaseNode
val ceaseOut = InModuleBody {
ceaseNode.makeIOs()
}

val wfiNode = IntSinkNode(IntSinkPortSimple())
wfiNode :=* rocketTile.wfiNode
val wfiOut = InModuleBody {
wfiNode.makeIOs()
}
val resetVectorNode = BundleBridgeSource(() => UInt(32.W))
rocketTile.resetVectorNode := resetVectorNode
val resetVector = InModuleBody {
resetVectorNode.makeIO()
}
val hartidNode = BundleBridgeSource(() => UInt(4.W))
rocketTile.hartIdNode := hartidNode
InModuleBody {
hartidNode.bundle := 0.U
}
val nmiNode = BundleBridgeSource(Some(() => new NMI(32)))
rocketTile.nmiNode := nmiNode
val nmi = InModuleBody {
nmiNode.makeIO()
}
Comment on lines +19 to +78
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These logic is already implemented in the InstantiatesTiles, please use it.

})
chisel3.experimental.DataMirror.fullModulePorts(
// instantiate the LazyModule
Module(ldut.module)
).filterNot(_._2.isInstanceOf[Aggregate]).foreach { case (name, ele) =>
if (!(name == "clock" || name == "reset")) {
chisel3.experimental.DataMirror.directionOf(ele) match {
case ActualDirection.Output =>
val io = IO(Output(chiselTypeOf(ele))).suggestName(name)
println(s"output $name")
io := ele
case ActualDirection.Input =>
val io = IO(Input(chiselTypeOf(ele))).suggestName(name)
println(s"input $name")
ele := io
}
}
}
Comment on lines +80 to +96
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IIRC this hack should be fixed.

}
Loading