package.scala 4.9 KB
Newer Older
1 2 3 4
import chisel3._
import chisel3.util._

package object xiangshan {
Y
YikeZhou 已提交
5
  object SrcType {
6 7 8 9
    def reg = "b00".U
    def pc  = "b01".U
    def imm = "b01".U
    def fp  = "b10".U
10

11
    def DC = imm // Don't Care
Y
YikeZhou 已提交
12

13 14 15
    def isReg(srcType: UInt) = srcType===reg
    def isPc(srcType: UInt) = srcType===pc
    def isImm(srcType: UInt) = srcType===imm
Z
ZhangZifei 已提交
16 17 18
    def isFp(srcType: UInt) = srcType===fp
    def isPcImm(srcType: UInt) = isPc(srcType) || isImm(srcType)
    def isRegFp(srcType: UInt) = isReg(srcType) || isFp(srcType)
19

20 21 22 23
    def apply() = UInt(2.W)
  }

  object SrcState {
Y
Yinan Xu 已提交
24 25 26 27
    def busy    = "b0".U
    def rdy     = "b1".U
    // def specRdy = "b10".U // speculative ready, for future use
    def apply() = UInt(1.W)
28 29 30
  }

  object FuType extends HasXSParameter {
L
LinJiawei 已提交
31 32 33 34 35
    def num           = exuParameters.NRFuType

    def jmp          = "b0000".U
    def i2f          = "b0001".U
    def csr          = "b0010".U
Y
Yinan Xu 已提交
36
    def alu          = "b0110".U
L
LinJiawei 已提交
37 38
    def mul          = "b0100".U
    def div          = "b0101".U
Y
Yinan Xu 已提交
39
    def fence        = "b0011".U
L
LinJiawei 已提交
40 41

    def fmac         = "b1000".U
Y
Yinan Xu 已提交
42
    def fmisc        = "b1011".U
L
LinJiawei 已提交
43 44 45 46
    def fDivSqrt     = "b1010".U

    def ldu          = "b1100".U
    def stu          = "b1101".U
Y
Yinan Xu 已提交
47
    def mou          = "b1111".U // for amo, lr, sc, fence
48 49 50

    def apply() = UInt(log2Up(num).W)

L
LinJiawei 已提交
51 52
    def isIntExu(fuType: UInt) = !fuType(3)
    def isJumpExu(fuType: UInt) = fuType === jmp
L
LinJiawei 已提交
53 54
    def isFpExu(fuType: UInt) = fuType(3, 2) === "b10".U
    def isMemExu(fuType: UInt) = fuType(3, 2) === "b11".U
Y
Yinan Xu 已提交
55 56
    def isLoadStore(fuType: UInt) = isMemExu(fuType) && !fuType(1)
    def isStoreExu(fuType: UInt) = isMemExu(fuType) && fuType(0)
Y
Yinan Xu 已提交
57
    def isAMO(fuType: UInt) = fuType(1)
Y
Yinan Xu 已提交
58 59 60 61 62 63 64 65 66 67 68 69

    def jmpCanAccept(fuType: UInt) = !fuType(2)
    def mduCanAccept(fuType: UInt) = fuType(2) && !fuType(1)
    def aluCanAccept(fuType: UInt) = fuType(2) && fuType(1)

    def fmacCanAccept(fuType: UInt) = !fuType(1)
    def fmiscCanAccept(fuType: UInt) = fuType(1)

    def loadCanAccept(fuType: UInt) = !fuType(0)
    def storeCanAccept(fuType: UInt) = fuType(0)

    def storeIsAMO(fuType: UInt) = fuType(1)
L
LinJiawei 已提交
70 71 72 73 74 75 76 77

    val functionNameMap = Map(
      jmp.litValue() -> "jmp",
      i2f.litValue() -> "int to float",
      csr.litValue() -> "csr",
      alu.litValue() -> "alu",
      mul.litValue() -> "mul",
      div.litValue() -> "div",
78
      fence.litValue() -> "fence",
L
LinJiawei 已提交
79 80 81 82 83 84 85
      fmac.litValue() -> "fmac",
      fmisc.litValue() -> "fmisc",
      fDivSqrt.litValue() -> "fdiv/fsqrt",
      ldu.litValue() -> "load",
      stu.litValue() -> "store"
    )

86 87 88
  }

  object FuOpType extends HasXSParameter {
L
LinJiawei 已提交
89
    def apply() = UInt(exuParameters.FuOpWidth.W)
90
  }
91 92 93 94 95 96 97 98 99

  object BTBtype {
    def B = "b00".U  // branch
    def J = "b01".U  // jump
    def I = "b10".U  // indirect
    def R = "b11".U  // return

    def apply() = UInt(2.W)
  }
100

101
  object CommitType {
Y
Yinan Xu 已提交
102 103 104 105
    def NORMAL = "b00".U  // int/fp
    def BRANCH = "b01".U  // branch
    def LOAD   = "b10".U  // load
    def STORE  = "b11".U  // store
106 107

    def apply() = UInt(2.W)
108
    def isLoadStore(commitType: UInt) = commitType(1)
109
    def lsInstIsStore(commitType: UInt) = commitType(0)
110
    def isStore(commitType: UInt) = isLoadStore(commitType) && lsInstIsStore(commitType)
Y
Yinan Xu 已提交
111
    def isBranch(commitType: UInt) = commitType(0) && !commitType(1)
112
  }
113 114 115 116 117 118 119 120 121 122 123 124

  object RedirectLevel {
    def flushAfter = "b00".U
    def flush      = "b01".U
    def flushAll   = "b10".U
    def exception  = "b11".U

    def apply() = UInt(2.W)
    def isUnconditional(level: UInt) = level(1)
    def flushItself(level: UInt) = level(0)
    def isException(level: UInt) = level(1) && level(0)
  }
125 126 127 128

  object ExceptionVec {
    def apply() = Vec(16, Bool())
  }
129

W
William Wang 已提交
130
  object PMAMode {
131 132 133 134 135 136
    def R = "b1".U << 0 //readable
    def W = "b1".U << 1 //writeable
    def X = "b1".U << 2 //executable
    def I = "b1".U << 3 //cacheable: icache
    def D = "b1".U << 4 //cacheable: dcache
    def S = "b1".U << 5 //enable speculative access
W
William Wang 已提交
137
    def A = "b1".U << 6 //enable atomic operation, A imply R & W
138
    def C = "b1".U << 7 //if it is cacheable is configable
W
William Wang 已提交
139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164
    def Reserved = "b0".U

    def apply() = UInt(7.W)

    def read(mode: UInt) = mode(0)
    def write(mode: UInt) = mode(1)
    def execute(mode: UInt) = mode(2)
    def icache(mode: UInt) = mode(3)
    def dcache(mode: UInt) = mode(4)
    def speculate(mode: UInt) = mode(5)
    def atomic(mode: UInt) = mode(6)
    def configable_cache(mode: UInt) = mode(7)

    def strToMode(s: String) = {
      var result = 0.U << 8
      if (s.toUpperCase.indexOf("R") >= 0) result = result + R
      if (s.toUpperCase.indexOf("W") >= 0) result = result + W
      if (s.toUpperCase.indexOf("X") >= 0) result = result + X
      if (s.toUpperCase.indexOf("I") >= 0) result = result + I
      if (s.toUpperCase.indexOf("D") >= 0) result = result + D
      if (s.toUpperCase.indexOf("S") >= 0) result = result + S
      if (s.toUpperCase.indexOf("A") >= 0) result = result + A
      if (s.toUpperCase.indexOf("C") >= 0) result = result + C
      result
    }
  }
165
}