Skip to content

Commit

Permalink
Bump difftest (OpenXiangShan#2579)
Browse files Browse the repository at this point in the history
  • Loading branch information
poemonsense authored Dec 24, 2023
1 parent eca28d5 commit fad4805
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 88 deletions.
36 changes: 2 additions & 34 deletions src/main/scala/device/AXI4DummySD.scala
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ package device

import org.chipsalliance.cde.config.Parameters
import chisel3._
import chisel3.experimental.ExtModule
import chisel3.util._
import difftest.common.DifftestSDCard
import freechips.rocketchip.diplomacy.AddressSet
import utility._

Expand All @@ -37,37 +37,6 @@ trait HasSDConst {
def C_SIZE = NrBlock / MULT - 1
}

class SDHelper extends ExtModule with HasExtModuleInline {
val clk = IO(Input(Clock()))
val ren = IO(Input(Bool()))
val data = IO(Output(UInt(32.W)))
val setAddr = IO(Input(Bool()))
val addr = IO(Input(UInt(32.W)))

setInline("SDHelper.v",
s"""
|import "DPI-C" function void sd_setaddr(input int addr);
|import "DPI-C" function void sd_read(output int data);
|
|module SDHelper (
| input clk,
| input setAddr,
| input [31:0] addr,
| input ren,
| output reg [31:0] data
|);
|
| always @(negedge clk) begin
| if (ren) sd_read(data);
| end
| always@(posedge clk) begin
| if (setAddr) sd_setaddr(addr);
| end
|
|endmodule
""".stripMargin)
}

class AXI4DummySD
(
address: Seq[AddressSet]
Expand Down Expand Up @@ -120,8 +89,7 @@ class AXI4DummySD
wdata
}

val sdHelper = Module(new SDHelper)
sdHelper.clk := clock
val sdHelper = DifftestSDCard()
sdHelper.ren := (getOffset(raddr) === 0x40.U && in.ar.fire)
sdHelper.setAddr := setAddr
sdHelper.addr := regs(sdarg)
Expand Down
39 changes: 3 additions & 36 deletions src/main/scala/device/AXI4Flash.scala
Original file line number Diff line number Diff line change
Expand Up @@ -18,41 +18,9 @@ package device

import chisel3._
import chisel3.util._
import difftest.common.DifftestFlash
import org.chipsalliance.cde.config.Parameters
import chisel3.experimental.ExtModule
import freechips.rocketchip.diplomacy.AddressSet
import utils._
import utility._

class FlashHelper extends ExtModule with HasExtModuleInline {
val clk = IO(Input(Clock()))
val ren = IO(Input(Bool()))
val data = IO(Output(UInt(64.W)))
val addr = IO(Input(UInt(32.W)))

setInline("FlashHelper.v",
s"""
|import "DPI-C" function void flash_read
|(
| input int addr,
| output longint data
|);
|
|module FlashHelper (
| input clk,
| input [31:0] addr,
| input ren,
| output reg [63:0] data
|);
|
| always @(posedge clk) begin
| if (ren) flash_read(addr, data);
| end
|
|endmodule
""".stripMargin)
}


class AXI4Flash
(
Expand All @@ -64,9 +32,8 @@ class AXI4Flash
override lazy val module = new AXI4SlaveModuleImp(this){
def getOffset(addr: UInt) = addr(15,0)

val flash = Module(new FlashHelper)
flash.clk := clock
flash.ren := in.ar.fire
val flash = DifftestFlash()
flash.en := in.ar.fire
flash.addr := Cat(0.U(16.W), getOffset(raddr))

in.r.bits.data := flash.data
Expand Down
28 changes: 11 additions & 17 deletions src/test/scala/top/SimTop.scala
Original file line number Diff line number Diff line change
Expand Up @@ -75,28 +75,22 @@ class SimTop(implicit p: Parameters) extends Module {
soc.io.systemjtag.part_number := 0.U(16.W)
soc.io.systemjtag.version := 0.U(4.W)

val io = IO(new Bundle(){
val logCtrl = new LogCtrlIO
val perfInfo = new PerfInfoIO
val uart = new UARTIO
})

simMMIO.io.uart <> io.uart

val timer = if (!debugOpts.FPGAPlatform && (debugOpts.EnableDebug || debugOpts.EnablePerfDebug)) GTimer() else WireDefault(0.U(64.W))
val logEnable =
if (!debugOpts.FPGAPlatform && (debugOpts.EnableDebug || debugOpts.EnablePerfDebug))
(timer >= io.logCtrl.log_begin) && (timer < io.logCtrl.log_end)
else WireDefault(false.B)
val clean = if (!debugOpts.FPGAPlatform && debugOpts.EnablePerfDebug) WireDefault(io.perfInfo.clean) else WireDefault(false.B)
val dump = if (!debugOpts.FPGAPlatform && debugOpts.EnablePerfDebug) WireDefault(io.perfInfo.dump) else WireDefault(false.B)
val difftest = DifftestModule.finish("XiangShan")

simMMIO.io.uart <> difftest.uart

val hasPerf = !debugOpts.FPGAPlatform && debugOpts.EnablePerfDebug
val hasLog = !debugOpts.FPGAPlatform && debugOpts.EnableDebug
val hasPerfLog = hasPerf || hasLog
val timer = if (hasPerfLog) GTimer() else WireDefault(0.U(64.W))
val logEnable = if (hasPerfLog) WireDefault(difftest.logCtrl.enable(timer)) else WireDefault(false.B)
val clean = if (hasPerf) WireDefault(difftest.perfCtrl.clean) else WireDefault(false.B)
val dump = if (hasPerf) WireDefault(difftest.perfCtrl.dump) else WireDefault(false.B)

dontTouch(timer)
dontTouch(logEnable)
dontTouch(clean)
dontTouch(dump)

DifftestModule.finish("XiangShan")
}

object SimTop extends App {
Expand Down

0 comments on commit fad4805

Please sign in to comment.