1 from enum
import Enum
, unique
4 from os
.path
import dirname
, join
5 from collections
import namedtuple
9 filedir
= os
.path
.dirname(os
.path
.abspath(__file__
))
10 basedir
= dirname(dirname(dirname(filedir
)))
11 tabledir
= join(basedir
, 'libreriscv')
12 tabledir
= join(tabledir
, 'openpower')
13 return join(tabledir
, 'isatables')
15 def find_wiki_file(name
):
16 filedir
= os
.path
.dirname(os
.path
.abspath(__file__
))
17 basedir
= dirname(dirname(dirname(filedir
)))
18 tabledir
= join(basedir
, 'libreriscv')
19 tabledir
= join(tabledir
, 'openpower')
20 tabledir
= join(tabledir
, 'isatables')
22 return join(find_wiki_dir(), name
)
26 file_path
= find_wiki_file(name
)
27 with
open(file_path
, 'r') as csvfile
:
28 reader
= csv
.DictReader(csvfile
)
32 # names of the fields in the tables that don't correspond to an enum
33 single_bit_flags
= ['inv A', 'inv out',
34 'cry out', 'BR', 'sgn ext', 'rsrv', '32b',
35 'sgn', 'lk', 'sgl pipe']
37 # default values for fields in the table
38 default_values
= {'unit': "NONE", 'internal op': "OP_ILLEGAL",
39 'in1': "RA", 'in2': 'NONE', 'in3': 'NONE', 'out': 'NONE',
43 'rc': 'NONE', 'cry in': 'ZERO', 'form': 'NONE'}
46 def get_signal_name(name
):
49 return name
.lower().replace(' ', '_')
51 # this corresponds to which Function Unit (pipeline-with-Reservation-Stations)
52 # is to process and guard the operation. they are roughly divided by having
53 # the same register input/output signature (X-Form, etc.)
103 # supported instructions: make sure to keep up-to-date with CSV files
104 # just like everything else
106 "NONE", "add", "addc", "addco", "adde", "addeo", "addi", "addic", "addic.",
107 "addis", "addme", "addmeo", "addo", "addze", "addzeo", "and", "andc",
108 "andi.", "andis.", "attn", "b", "bc", "bcctr", "bclr", "bctar",
109 "bpermd", "cmp", "cmpb", "cmpeqb", "cmpi", "cmpl", "cmpli", "cmprb",
110 "cntlzd", "cntlzw", "cnttzd", "cnttzw", "crand", "crandc", "creqv",
111 "crnand", "crnor", "cror", "crorc", "crxor", "darn", "dcbf", "dcbst",
112 "dcbt", "dcbtst", "dcbz", "divd", "divde", "divdeo", "divdeu",
113 "divdeuo", "divdo", "divdu", "divduo", "divw", "divwe", "divweo",
114 "divweu", "divweuo", "divwo", "divwu", "divwuo", "eqv", "extsb",
115 "extsh", "extsw", "extswsli", "hrfid", "icbi", "icbt", "isel", "isync",
116 "lbarx", "lbz", "lbzu", "lbzux", "lbzx", "ld", "ldarx", "ldbrx",
117 "ldu", "ldux", "ldx", "lha", "lharx", "lhau", "lhaux", "lhax",
118 "lhbrx", "lhz", "lhzu", "lhzux", "lhzx", "lwa", "lwarx", "lwaux",
119 "lwax", "lwbrx", "lwz", "lwzcix", "lwzu", "lwzux", "lwzx", "mcrf", "mcrxr",
120 "mcrxrx", "mfcr/mfocrf", "mfmsr", "mfspr", "modsd", "modsw", "modud",
121 "moduw", "mtcrf/mtocrf", "mtmsr", "mtmsrd", "mtspr", "mulhd", "mulhdu",
122 "mulhw", "mulhwu", "mulld", "mulldo", "mulli", "mullw", "mullwo",
123 "nand", "neg", "nego", "nop", "nor", "or", "orc", "ori", "oris",
124 "popcntb", "popcntd", "popcntw", "prtyd", "prtyw", "rfid", "rldcl",
125 "rldcr", "rldic", "rldicl", "rldicr", "rldimi", "rlwimi", "rlwinm",
126 "rlwnm", "setb", "sim_cfg", "slbia", "sld", "slw", "srad", "sradi", "sraw",
127 "srawi", "srd", "srw", "stb", "stbcix", "stbcx", "stbu", "stbux", "stbx",
128 "std", "stdbrx", "stdcx", "stdu", "stdux", "stdx", "sth", "sthbrx", "sthcx",
129 "sthu", "sthux", "sthx", "stw", "stwbrx", "stwcx", "stwu", "stwux",
130 "stwx", "subf", "subfc", "subfco", "subfe", "subfeo", "subfic",
131 "subfme", "subfmeo", "subfo", "subfze", "subfzeo", "sync", "td",
132 "tdi", "tlbie", "tlbiel", "tw", "twi", "xor", "xori", "xoris",
135 # two-way lookup of instruction-to-index and vice-versa
138 for i
, insn
in enumerate(_insns
):
142 # Internal Operation numbering. Add new opcodes here (FPADD, FPMUL etc.)
145 OP_ILLEGAL
= 0 # important that this is zero (see power_decoder.py)
226 RS
= 4 # for some ALU/Logical operations
244 RS
= 13 # for shiftrot (M-Form)
251 RB
= 2 # for shiftrot (M-Form)
272 class LDSTMode(Enum
):
307 class CROutSel(Enum
):
316 # SPRs - Special-Purpose Registers. See V3.0B Figure 18 p971 and
317 # http://libre-riscv.org/openpower/isatables/sprs.csv
318 # http://bugs.libre-riscv.org/show_bug.cgi?id=261
320 spr_csv
= get_csv("sprs.csv")
321 spr_info
= namedtuple('spr_info', 'SPR priv_mtspr priv_mfspr length idx')
325 info
= spr_info(SPR
=row
['SPR'], priv_mtspr
=row
['priv_mtspr'],
326 priv_mfspr
=row
['priv_mfspr'], length
=int(row
['len']),
328 spr_dict
[int(row
['Idx'])] = info
329 spr_byname
[row
['SPR']] = info
330 fields
= [(row
['SPR'], int(row
['Idx'])) for row
in spr_csv
]
331 SPR
= Enum('SPR', fields
)
342 if __name__
== '__main__':
343 # find out what the heck is in SPR enum :)
344 print("sprs", len(SPR
))
347 print(SPR
.__members
__['TAR'])
349 print(x
, x
.value
, str(x
), x
.name
)
351 print ("function", Function
.ALU
.name
)