1import chisel3._ 2import chisel3.util._ 3 4package object xiangshan { 5 object SrcType { 6 def reg = "b00".U 7 def pc = "b01".U 8 def imm = "b01".U 9 def fp = "b10".U 10 11 def DC = imm // Don't Care 12 13 def isReg(srcType: UInt) = srcType===reg 14 def isPc(srcType: UInt) = srcType===pc 15 def isImm(srcType: UInt) = srcType===imm 16 def isFp(srcType: UInt) = srcType===fp 17 def isPcImm(srcType: UInt) = isPc(srcType) || isImm(srcType) 18 def isRegFp(srcType: UInt) = isReg(srcType) || isFp(srcType) 19 20 def apply() = UInt(2.W) 21 } 22 23 object SrcState { 24 def busy = "b0".U 25 def rdy = "b1".U 26 // def specRdy = "b10".U // speculative ready, for future use 27 def apply() = UInt(1.W) 28 } 29 30 object FuType extends HasXSParameter { 31 def num = exuParameters.NRFuType 32 33 def jmp = "b0000".U 34 def i2f = "b0001".U 35 def csr = "b0010".U 36 def alu = "b0110".U 37 def mul = "b0100".U 38 def div = "b0101".U 39 def fence = "b0011".U 40 41 def fmac = "b1000".U 42 def fmisc = "b1011".U 43 def fDivSqrt = "b1010".U 44 45 def ldu = "b1100".U 46 def stu = "b1101".U 47 def mou = "b1111".U // for amo, lr, sc, fence 48 49 def apply() = UInt(log2Up(num).W) 50 51 def isIntExu(fuType: UInt) = !fuType(3) 52 def isJumpExu(fuType: UInt) = fuType === jmp 53 def isFpExu(fuType: UInt) = fuType(3, 2) === "b10".U 54 def isMemExu(fuType: UInt) = fuType(3, 2) === "b11".U 55 def isLoadStore(fuType: UInt) = isMemExu(fuType) && !fuType(1) 56 def isStoreExu(fuType: UInt) = isMemExu(fuType) && fuType(0) 57 def isAMO(fuType: UInt) = fuType(1) 58 59 def jmpCanAccept(fuType: UInt) = !fuType(2) 60 def mduCanAccept(fuType: UInt) = fuType(2) && !fuType(1) 61 def aluCanAccept(fuType: UInt) = fuType(2) && fuType(1) 62 63 def fmacCanAccept(fuType: UInt) = !fuType(1) 64 def fmiscCanAccept(fuType: UInt) = fuType(1) 65 66 def loadCanAccept(fuType: UInt) = !fuType(0) 67 def storeCanAccept(fuType: UInt) = fuType(0) 68 69 def storeIsAMO(fuType: UInt) = fuType(1) 70 71 val functionNameMap = Map( 72 jmp.litValue() -> "jmp", 73 i2f.litValue() -> "int to float", 74 csr.litValue() -> "csr", 75 alu.litValue() -> "alu", 76 mul.litValue() -> "mul", 77 div.litValue() -> "div", 78 fence.litValue() -> "fence", 79 fmac.litValue() -> "fmac", 80 fmisc.litValue() -> "fmisc", 81 fDivSqrt.litValue() -> "fdiv/fsqrt", 82 ldu.litValue() -> "load", 83 stu.litValue() -> "store" 84 ) 85 86 } 87 88 object FuOpType extends HasXSParameter { 89 def apply() = UInt(exuParameters.FuOpWidth.W) 90 } 91 92 object BTBtype { 93 def B = "b00".U // branch 94 def J = "b01".U // jump 95 def I = "b10".U // indirect 96 def R = "b11".U // return 97 98 def apply() = UInt(2.W) 99 } 100 101 object CommitType { 102 def NORMAL = "b00".U // int/fp 103 def BRANCH = "b01".U // branch 104 def LOAD = "b10".U // load 105 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) 111 def isBranch(commitType: UInt) = commitType(0) && !commitType(1) 112 } 113 114 object RedirectLevel { 115 def flushAfter = "b0".U 116 def flush = "b1".U 117 118 def apply() = UInt(1.W) 119 // def isUnconditional(level: UInt) = level(1) 120 def flushItself(level: UInt) = level(0) 121 // def isException(level: UInt) = level(1) && level(0) 122 } 123 124 object ExceptionVec { 125 def apply() = Vec(16, Bool()) 126 } 127 128 object PMAMode { 129 def R = "b1".U << 0 //readable 130 def W = "b1".U << 1 //writeable 131 def X = "b1".U << 2 //executable 132 def I = "b1".U << 3 //cacheable: icache 133 def D = "b1".U << 4 //cacheable: dcache 134 def S = "b1".U << 5 //enable speculative access 135 def A = "b1".U << 6 //enable atomic operation, A imply R & W 136 def C = "b1".U << 7 //if it is cacheable is configable 137 def Reserved = "b0".U 138 139 def apply() = UInt(7.W) 140 141 def read(mode: UInt) = mode(0) 142 def write(mode: UInt) = mode(1) 143 def execute(mode: UInt) = mode(2) 144 def icache(mode: UInt) = mode(3) 145 def dcache(mode: UInt) = mode(4) 146 def speculate(mode: UInt) = mode(5) 147 def atomic(mode: UInt) = mode(6) 148 def configable_cache(mode: UInt) = mode(7) 149 150 def strToMode(s: String) = { 151 var result = 0.U << 8 152 if (s.toUpperCase.indexOf("R") >= 0) result = result + R 153 if (s.toUpperCase.indexOf("W") >= 0) result = result + W 154 if (s.toUpperCase.indexOf("X") >= 0) result = result + X 155 if (s.toUpperCase.indexOf("I") >= 0) result = result + I 156 if (s.toUpperCase.indexOf("D") >= 0) result = result + D 157 if (s.toUpperCase.indexOf("S") >= 0) result = result + S 158 if (s.toUpperCase.indexOf("A") >= 0) result = result + A 159 if (s.toUpperCase.indexOf("C") >= 0) result = result + C 160 result 161 } 162 } 163} 164