1 from enum
import Enum
, unique
4 from os
.path
import dirname
, join
5 from collections
import namedtuple
7 def find_wiki_file(name
):
8 filedir
= os
.path
.dirname(os
.path
.abspath(__file__
))
9 basedir
= dirname(dirname(dirname(filedir
)))
10 tabledir
= join(basedir
, 'libreriscv')
11 tabledir
= join(tabledir
, 'openpower')
12 tabledir
= join(tabledir
, 'isatables')
14 file_path
= join(tabledir
, name
)
19 file_path
= find_wiki_file(name
)
20 with
open(file_path
, 'r') as csvfile
:
21 reader
= csv
.DictReader(csvfile
)
25 # names of the fields in the tables that don't correspond to an enum
26 single_bit_flags
= ['CR in', 'CR out', 'inv A', 'inv out',
27 'cry out', 'BR', 'sgn ext', 'upd', 'rsrv', '32b',
28 'sgn', 'lk', 'sgl pipe']
30 # default values for fields in the table
31 default_values
= {'unit': "NONE", 'internal op': "OP_ILLEGAL",
32 'in1': "RA", 'in2': 'NONE', 'in3': 'NONE', 'out': 'NONE',
34 'rc': 'NONE', 'cry in': 'ZERO', 'form': 'NONE'}
37 def get_signal_name(name
):
40 return name
.lower().replace(' ', '_')
83 # Internal Operation numbering. Add new opcodes here (FPADD, FPMUL etc.)
85 class InternalOp(Enum
):
86 OP_ILLEGAL
= 0 # important that this is zero (see power_decoder.py)
219 # SPRs - Special-Purpose Registers. See V3.0B Figure 18 p971 and
220 # http://libre-riscv.org/openpower/isatables/sprs.csv
221 # http://bugs.libre-riscv.org/show_bug.cgi?id=261
223 spr_csv
= get_csv("sprs.csv")
224 spr_info
= namedtuple('spr_info', 'SPR priv_mtspr priv_mfspr length')
227 info
= spr_info(SPR
=row
['SPR'], priv_mtspr
=row
['priv_mtspr'],
228 priv_mfspr
=row
['priv_mfspr'], length
=int(row
['len']))
229 spr_dict
[int(row
['Idx'])] = info
230 fields
= [(row
['SPR'], int(row
['Idx'])) for row
in spr_csv
]
231 SPR
= Enum('SPR', fields
)