attempting to add SPRs to rfid test
[soc.git] / src / soc / decoder / power_enums.py
index 93c6b07b48cdd7a9d17010d7f8d43c73c6323f97..931101ecb0aea1c5237ea4b34da5ae01164ecadd 100644 (file)
@@ -23,13 +23,14 @@ def get_csv(name):
 
 
 # names of the fields in the tables that don't correspond to an enum
-single_bit_flags = ['CR in', 'CR out', 'inv A', 'inv out',
+single_bit_flags = ['inv A', 'inv out',
                     'cry out', 'BR', 'sgn ext', 'upd', 'rsrv', '32b',
                     'sgn', 'lk', 'sgl pipe']
 
 # default values for fields in the table
 default_values = {'unit': "NONE", 'internal op': "OP_ILLEGAL",
                   'in1': "RA", 'in2': 'NONE', 'in3': 'NONE', 'out': 'NONE',
+                  'CR in': 'NONE',
                   'ldst len': 'NONE',
                   'rc': 'NONE', 'cry in': 'ZERO', 'form': 'NONE'}
 
@@ -39,13 +40,21 @@ def get_signal_name(name):
         name = "is_" + name
     return name.lower().replace(' ', '_')
 
-
+# this corresponds to which Function Unit (pipeline-with-Reservation-Stations)
+# is to process and guard the operation.  they are roughly divided by having
+# the same register input/output signature (X-Form, etc.)
 @unique
 class Function(Enum):
     NONE = 0
-    ALU = 1
-    LDST = 2
-    SHIFT_ROT = 3
+    ALU = 1<<1
+    LDST = 1<<2
+    SHIFT_ROT = 1<<3
+    LOGICAL = 1<<4
+    BRANCH = 1<<5
+    CR = 1<<6
+    TRAP = 1<<7
+    MUL = 1<<8
+    DIV = 1<<9
 
 
 @unique
@@ -80,6 +89,44 @@ class Form(Enum):
     Z22 = 27
     Z23 = 28
 
+# supported instructions: make sure to keep up-to-date with CSV files
+# just like everything else
+_insns = [
+    "NONE", "add", "addc", "addco", "adde", "addeo", "addi", "addic", "addic.",
+    "addis", "addme", "addmeo", "addo", "addze", "addzeo", "and", "andc",
+    "andi.", "andis.", "attn", "b", "bc", "bcctr", "bclr", "bctar",
+    "bpermd", "cmp", "cmpb", "cmpeqb", "cmpi", "cmpl", "cmpli", "cmprb",
+    "cntlzd", "cntlzw", "cnttzd", "cnttzw", "crand", "crandc", "creqv",
+    "crnand", "crnor", "cror", "crorc", "crxor", "darn", "dcbf", "dcbst",
+    "dcbt", "dcbtst", "dcbz", "divd", "divde", "divdeo", "divdeu",
+    "divdeuo", "divdo", "divdu", "divduo", "divw", "divwe", "divweo",
+    "divweu", "divweuo", "divwo", "divwu", "divwuo", "eqv", "extsb",
+    "extsh", "extsw", "extswsli", "icbi", "icbt", "isel", "isync",
+    "lbarx", "lbz", "lbzu", "lbzux", "lbzx", "ld", "ldarx", "ldbrx",
+    "ldu", "ldux", "ldx", "lha", "lharx", "lhau", "lhaux", "lhax",
+    "lhbrx", "lhz", "lhzu", "lhzux", "lhzx", "lwa", "lwarx", "lwaux",
+    "lwax", "lwbrx", "lwz", "lwzu", "lwzux", "lwzx", "mcrf", "mcrxr",
+    "mcrxrx", "mfcr/mfocrf", "mfmsr", "mfspr", "modsd", "modsw", "modud",
+    "moduw", "mtcrf/mtocrf", "mtmsrd", "mtspr", "mulhd", "mulhdu",
+    "mulhw", "mulhwu", "mulld", "mulldo", "mulli", "mullw", "mullwo",
+    "nand", "neg", "nego", "nop", "nor", "or", "orc", "ori", "oris",
+    "popcntb", "popcntd", "popcntw", "prtyd", "prtyw", "rfid", "rldcl",
+    "rldcr", "rldic", "rldicl", "rldicr", "rldimi", "rlwimi", "rlwinm",
+    "rlwnm", "setb", "sim_cfg", "sld", "slw", "srad", "sradi", "sraw",
+    "srawi", "srd", "srw", "stb", "stbcx", "stbu", "stbux", "stbx", "std",
+    "stdbrx", "stdcx", "stdu", "stdux", "stdx", "sth", "sthbrx", "sthcx",
+    "sthu", "sthux", "sthx", "stw", "stwbrx", "stwcx", "stwu", "stwux",
+    "stwx", "subf", "subfc", "subfco", "subfe", "subfeo", "subfic",
+    "subfme", "subfmeo", "subfo", "subfze", "subfzeo", "sync", "td",
+    "tdi", "tw", "twi", "xor", "xori", "xoris",
+]
+
+# two-way lookup of instruction-to-index and vice-versa
+insns = {}
+asmidx = {}
+for i, insn in enumerate(_insns):
+    insns[i] = insn
+    asmidx[insn] = i
 
 # Internal Operation numbering.  Add new opcodes here (FPADD, FPMUL etc.)
 @unique
@@ -147,12 +194,14 @@ class InternalOp(Enum):
     OP_SHL = 60
     OP_SHR = 61
     OP_SYNC = 62
-    OP_TD = 63
-    OP_TDI = 64
-    OP_TW = 65
-    OP_TWI = 66
+    OP_TRAP = 63
     OP_XOR = 67
     OP_SIM_CONFIG = 68
+    OP_CROP = 69
+    OP_RFID = 70
+    OP_MFMSR = 71
+    OP_MTMSRD = 72
+    OP_SC = 73
 
 
 @unique
@@ -161,6 +210,7 @@ class In1Sel(Enum):
     RA = 1
     RA_OR_ZERO = 2
     SPR = 3
+    RS = 4  # for some ALU/Logical operations
 
 
 @unique
@@ -178,12 +228,14 @@ class In2Sel(Enum):
     CONST_SH = 10
     CONST_SH32 = 11
     SPR = 12
+    RS = 13 # for shiftrot (M-Form)
 
 
 @unique
 class In3Sel(Enum):
     NONE = 0
     RS = 1
+    RB = 2 # for shiftrot (M-Form)
 
 
 @unique
@@ -199,8 +251,8 @@ class LdstLen(Enum):
     NONE = 0
     is1B = 1
     is2B = 2
-    is4B = 3
-    is8B = 4
+    is4B = 4
+    is8B = 8
 
 
 @unique
@@ -216,6 +268,24 @@ class CryIn(Enum):
     ONE = 1
     CA = 2
 
+@unique
+class CRInSel(Enum):
+    NONE = 0
+    CR0 = 1
+    BI = 2
+    BFA = 3
+    BA_BB = 4
+    BC = 5
+    WHOLE_REG = 6
+
+@unique
+class CROutSel(Enum):
+    NONE = 0
+    CR0 = 1
+    BF = 2
+    BT = 3
+    WHOLE_REG = 4
+
 
 # SPRs - Special-Purpose Registers.  See V3.0B Figure 18 p971 and
 # http://libre-riscv.org/openpower/isatables/sprs.csv
@@ -224,10 +294,12 @@ class CryIn(Enum):
 spr_csv = get_csv("sprs.csv")
 spr_info = namedtuple('spr_info', 'SPR priv_mtspr priv_mfspr length')
 spr_dict = {}
+spr_byname = {}
 for row in spr_csv:
     info = spr_info(SPR=row['SPR'], priv_mtspr=row['priv_mtspr'],
                     priv_mfspr=row['priv_mfspr'], length=int(row['len']))
     spr_dict[int(row['Idx'])] = info
+    spr_byname[row['SPR']] = info
 fields = [(row['SPR'], int(row['Idx'])) for row in spr_csv]
 SPR = Enum('SPR', fields)
 
@@ -239,3 +311,12 @@ XER_bits = {
     'OV32': 44,
     'CA32': 45
     }
+
+if __name__ == '__main__':
+    # find out what the heck is in SPR enum :)
+    print ("sprs", len(SPR))
+    print (dir(SPR))
+    print (dir(Enum))
+    print (SPR.__members__['TAR'])
+    for x in SPR:
+        print (x, x.value, str(x), x.name)