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 = "b00".U 25 def rdy = "b01".U 26 def specRdy = "b10".U // speculative ready, for future use 27 def apply() = UInt(2.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 = "b0011".U 37 def mul = "b0100".U 38 def div = "b0101".U 39 def fence = "b0110".U 40 41 def fmac = "b1000".U 42 def fmisc = "b1001".U 43 def fDivSqrt = "b1010".U 44 45 def ldu = "b1100".U 46 def stu = "b1101".U 47 def mou = "b1110".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 isLoadExu(fuType: UInt) = fuType === ldu || fuType === mou 56 def isStoreExu(fuType: UInt) = fuType === stu 57 58 val functionNameMap = Map( 59 jmp.litValue() -> "jmp", 60 i2f.litValue() -> "int to float", 61 csr.litValue() -> "csr", 62 alu.litValue() -> "alu", 63 mul.litValue() -> "mul", 64 div.litValue() -> "div", 65 fence.litValue() -> "fence", 66 fmac.litValue() -> "fmac", 67 fmisc.litValue() -> "fmisc", 68 fDivSqrt.litValue() -> "fdiv/fsqrt", 69 ldu.litValue() -> "load", 70 stu.litValue() -> "store" 71 ) 72 73 } 74 75 object FuOpType extends HasXSParameter { 76 def apply() = UInt(exuParameters.FuOpWidth.W) 77 } 78 79 object BTBtype { 80 def B = "b00".U // branch 81 def J = "b01".U // jump 82 def I = "b10".U // indirect 83 def R = "b11".U // return 84 85 def apply() = UInt(2.W) 86 } 87 88 object CommitType { 89 def NORMAL = "b00".U // int/fp 90 def BRANCH = "b01".U // branch 91 def LOAD = "b10".U // load 92 def STORE = "b11".U // store 93 94 def apply() = UInt(2.W) 95 def isLoadStore(commitType: UInt) = commitType(1) 96 def lsInstIsStore(commitType: UInt) = commitType(0) 97 def isStore(commitType: UInt) = isLoadStore(commitType) && lsInstIsStore(commitType) 98 def isBranch(commitType: UInt) = commitType(0) && !commitType(1) 99 } 100 101 object RedirectLevel { 102 def flushAfter = "b0".U 103 def flush = "b1".U 104 105 def apply() = UInt(1.W) 106 // def isUnconditional(level: UInt) = level(1) 107 def flushItself(level: UInt) = level(0) 108 // def isException(level: UInt) = level(1) && level(0) 109 } 110 111 object ExceptionVec { 112 def apply() = Vec(16, Bool()) 113 } 114 115 object PMAMode { 116 def R = "b1".U << 0 //readable 117 def W = "b1".U << 1 //writeable 118 def X = "b1".U << 2 //executable 119 def I = "b1".U << 3 //cacheable: icache 120 def D = "b1".U << 4 //cacheable: dcache 121 def S = "b1".U << 5 //enable speculative access 122 def A = "b1".U << 6 //enable atomic operation, A imply R & W 123 def C = "b1".U << 7 //if it is cacheable is configable 124 def Reserved = "b0".U 125 126 def apply() = UInt(7.W) 127 128 def read(mode: UInt) = mode(0) 129 def write(mode: UInt) = mode(1) 130 def execute(mode: UInt) = mode(2) 131 def icache(mode: UInt) = mode(3) 132 def dcache(mode: UInt) = mode(4) 133 def speculate(mode: UInt) = mode(5) 134 def atomic(mode: UInt) = mode(6) 135 def configable_cache(mode: UInt) = mode(7) 136 137 def strToMode(s: String) = { 138 var result = 0.U << 8 139 if (s.toUpperCase.indexOf("R") >= 0) result = result + R 140 if (s.toUpperCase.indexOf("W") >= 0) result = result + W 141 if (s.toUpperCase.indexOf("X") >= 0) result = result + X 142 if (s.toUpperCase.indexOf("I") >= 0) result = result + I 143 if (s.toUpperCase.indexOf("D") >= 0) result = result + D 144 if (s.toUpperCase.indexOf("S") >= 0) result = result + S 145 if (s.toUpperCase.indexOf("A") >= 0) result = result + A 146 if (s.toUpperCase.indexOf("C") >= 0) result = result + C 147 result 148 } 149 } 150} 151