Memend.scala 4.9 KB
Newer Older
Y
Yinan Xu 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83
package xiangshan.mem

import chisel3._
import chisel3.util._
import xiangshan._
import utils._
import xiangshan.cache._
import bus.simplebus._

object LSUOpType {
  def lb   = "b000000".U
  def lh   = "b000001".U
  def lw   = "b000010".U
  def ld   = "b000011".U
  def lbu  = "b000100".U
  def lhu  = "b000101".U
  def lwu  = "b000110".U
  def ldu  = "b000111".U
  def sb   = "b001000".U
  def sh   = "b001001".U
  def sw   = "b001010".U
  def sd   = "b001011".U

  def lr      = "b100010".U
  def sc      = "b100011".U
  def amoswap = "b100001".U
  def amoadd  = "b100000".U
  def amoxor  = "b100100".U
  def amoand  = "b101100".U
  def amoor   = "b101000".U
  def amomin  = "b110000".U
  def amomax  = "b110100".U
  def amominu = "b111000".U
  def amomaxu = "b111100".U

  def isStore(func: UInt): Bool = func(3)
  def isAtom(func: UInt): Bool = func(5)

  def atomW = "010".U
  def atomD = "011".U
}

object genWmask {
  def apply(addr: UInt, sizeEncode: UInt): UInt = {
    (LookupTree(sizeEncode, List(
      "b00".U -> 0x1.U, //0001 << addr(2:0)
      "b01".U -> 0x3.U, //0011
      "b10".U -> 0xf.U, //1111
      "b11".U -> 0xff.U //11111111
    )) << addr(2, 0)).asUInt()
  }
}

object genWdata {
  def apply(data: UInt, sizeEncode: UInt): UInt = {
    LookupTree(sizeEncode, List(
      "b00".U -> Fill(8, data(7, 0)),
      "b01".U -> Fill(4, data(15, 0)),
      "b10".U -> Fill(2, data(31, 0)),
      "b11".U -> data
    ))
  }
}

class LsPipelineBundle extends XSBundle {
  val vaddr = UInt(VAddrBits.W)
  val paddr = UInt(PAddrBits.W)
  val func = UInt(6.W)
  val mask = UInt(8.W)
  val data = UInt(XLEN.W)
  val uop = new MicroOp

  val miss = Bool()
  val mmio = Bool()
  val rollback = Bool()

  val forwardMask = Vec(8, Bool())
  val forwardData = Vec(8, UInt(8.W))
}

class LoadForwardQueryIO extends XSBundle {
  val paddr = Output(UInt(PAddrBits.W))
  val mask = Output(UInt(8.W))
Y
Yinan Xu 已提交
84
  val lsroqIdx = Output(UInt(LsroqIdxWidth.W))
Y
Yinan Xu 已提交
85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101
  val pc = Output(UInt(VAddrBits.W)) //for debug
  val valid = Output(Bool()) //for debug

  val forwardMask = Input(Vec(8, Bool()))
  val forwardData = Input(Vec(8, UInt(8.W)))
}

class MemToBackendIO extends XSBundle {
  val ldin = Vec(exuParameters.LduCnt, Flipped(Decoupled(new ExuInput)))
  val stin = Vec(exuParameters.StuCnt, Flipped(Decoupled(new ExuInput)))
  val ldout = Vec(exuParameters.LduCnt, Decoupled(new ExuOutput))
  val stout = Vec(exuParameters.StuCnt, Decoupled(new ExuOutput))
  val redirect = Flipped(ValidIO(new Redirect))
  // replay all instructions form dispatch
  val replayAll = ValidIO(new Redirect)
  // replay mem instructions form Load Queue/Store Queue
  val tlbFeedback = Vec(exuParameters.LduCnt + exuParameters.LduCnt, ValidIO(new TlbFeedback))
102
  val commits = Flipped(Vec(CommitWidth, Valid(new RoqCommit)))
Y
Yinan Xu 已提交
103
  val dp1Req = Vec(RenameWidth, Flipped(DecoupledIO(new MicroOp)))
Y
Yinan Xu 已提交
104
  val lsroqIdxs = Output(Vec(RenameWidth, UInt(LsroqIdxWidth.W)))
Y
Yinan Xu 已提交
105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150
}

class Memend extends XSModule {
  val io = IO(new Bundle{
    val backend = new MemToBackendIO
    val dmem = new SimpleBusUC(userBits = (new DcacheUserBundle).getWidth)
  })

  val loadUnits = (0 until exuParameters.LduCnt).map(_ => Module(new LoadUnit))
  val storeUnits = (0 until exuParameters.StuCnt).map(_ => Module(new StoreUnit))
  val dcache = Module(new Dcache)
  // val mshq = Module(new MSHQ)
  val dtlb = Module(new Dtlb)
  val lsroq = Module(new Lsroq)
  val sbuffer = Module(new FakeSbuffer)

  dcache.io := DontCare
  dtlb.io := DontCare
  // mshq.io := DontCare

  for (i <- 0 until exuParameters.LduCnt) {
    loadUnits(i).io.ldin <> io.backend.ldin(i)
    loadUnits(i).io.ldout <> io.backend.ldout(i)
    loadUnits(i).io.redirect <> io.backend.redirect
    loadUnits(i).io.tlbFeedback <> io.backend.tlbFeedback(i)
    loadUnits(i).io.dcache <> dcache.io.lsu.load(i)
    loadUnits(i).io.dtlb <> dtlb.io.lsu(i)
    loadUnits(i).io.sbuffer <> sbuffer.io.forward(i)

    lsroq.io.loadIn(i) <> loadUnits(i).io.lsroq.loadIn
    lsroq.io.ldout(i) <> loadUnits(i).io.lsroq.ldout
    lsroq.io.forward(i) <> loadUnits(i).io.lsroq.forward
  }

  for (i <- 0 until exuParameters.StuCnt) {
    storeUnits(i).io.stin <> io.backend.stin(i)
    storeUnits(i).io.redirect <> io.backend.redirect
    storeUnits(i).io.tlbFeedback <> io.backend.tlbFeedback(exuParameters.LduCnt + i)
    storeUnits(i).io.dtlb <> dtlb.io.lsu(exuParameters.LduCnt + i)
    storeUnits(i).io.lsroq <> lsroq.io.storeIn(i)
  }

  dcache.io.lsu.refill <> DontCare // TODO
  sbuffer.io.dcache <> dcache.io.lsu.store

  lsroq.io.stout <> io.backend.stout
151
  lsroq.io.commits <> io.backend.commits
Y
Yinan Xu 已提交
152
  lsroq.io.dp1Req <> io.backend.dp1Req
Y
Yinan Xu 已提交
153
  lsroq.io.lsroqIdxs <> io.backend.lsroqIdxs
Y
Yinan Xu 已提交
154 155 156 157 158 159 160 161 162 163 164
  lsroq.io.brqRedirect := io.backend.redirect
  io.backend.replayAll <> lsroq.io.rollback

  lsroq.io.refill <> DontCare
  lsroq.io.refill.valid := false.B // TODO
  lsroq.io.miss <> DontCare //TODO
  // LSROQ to store buffer
  lsroq.io.sbuffer <> sbuffer.io.in
  // for ls pipeline test
  dcache.io.dmem <> io.dmem
  dcache.io.lsu.refill <> DontCare
Y
Yinan Xu 已提交
165
}