Read decoder tables from wiki submodule instead of web
[soc.git] / src / soc / decoder / power_enums.py
1 from enum import Enum, unique
2 import csv
3 import os
4 import requests
5 from os.path import dirname, join
6
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')
13
14 file_path = join(tabledir, name)
15 return file_path
16
17
18 def get_csv(name):
19 file_path = find_wiki_file(name)
20 with open(file_path, 'r') as csvfile:
21 reader = csv.DictReader(csvfile)
22 return list(reader)
23
24
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']
29
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',
33 'ldst len': 'NONE',
34 'rc': 'NONE', 'cry in': 'ZERO', 'form': 'NONE'}
35
36
37 def get_signal_name(name):
38 if name[0].isdigit():
39 name = "is_" + name
40 return name.lower().replace(' ', '_')
41
42
43 @unique
44 class Function(Enum):
45 NONE = 0
46 ALU = 1
47 LDST = 2
48
49
50 @unique
51 class Form(Enum):
52 NONE = 0
53 I = 1
54 B = 2
55 SC = 3
56 D = 4
57 DS = 5
58 DQ = 6
59 DX = 7
60 X = 8
61 XL = 9
62 XFX = 10
63 XFL = 11
64 XX1 = 12
65 XX2 = 13
66 XX3 = 14
67 XX4 = 15
68 XS = 16
69 XO = 17
70 A = 18
71 M = 19
72 MD = 20
73 MDS = 21
74 VA = 22
75 VC = 23
76 VX = 24
77 EVX = 25
78 EVS = 26
79 Z22 = 27
80 Z23 = 28
81
82
83 # Internal Operation numbering. Add new opcodes here (FPADD, FPMUL etc.)
84 @unique
85 class InternalOp(Enum):
86 OP_ILLEGAL = 0 # important that this is zero (see power_decoder.py)
87 OP_NOP = 1
88 OP_ADD = 2
89 OP_ADDPCIS = 3
90 OP_AND = 4
91 OP_ATTN = 5
92 OP_B = 6
93 OP_BC = 7
94 OP_BCREG = 8
95 OP_BPERM = 9
96 OP_CMP = 10
97 OP_CMPB = 11
98 OP_CMPEQB = 12
99 OP_CMPRB = 13
100 OP_CNTZ = 14
101 OP_CRAND = 15
102 OP_CRANDC = 16
103 OP_CREQV = 17
104 OP_CRNAND = 18
105 OP_CRNOR = 19
106 OP_CROR = 20
107 OP_CRORC = 21
108 OP_CRXOR = 22
109 OP_DARN = 23
110 OP_DCBF = 24
111 OP_DCBST = 25
112 OP_DCBT = 26
113 OP_DCBTST = 27
114 OP_DCBZ = 28
115 OP_DIV = 29
116 OP_DIVE = 30
117 OP_EXTS = 31
118 OP_EXTSWSLI = 32
119 OP_ICBI = 33
120 OP_ICBT = 34
121 OP_ISEL = 35
122 OP_ISYNC = 36
123 OP_LOAD = 37
124 OP_STORE = 38
125 OP_MADDHD = 39
126 OP_MADDHDU = 40
127 OP_MADDLD = 41
128 OP_MCRF = 42
129 OP_MCRXR = 43
130 OP_MCRXRX = 44
131 OP_MFCR = 45
132 OP_MFSPR = 46
133 OP_MOD = 47
134 OP_MTCRF = 48
135 OP_MTSPR = 49
136 OP_MUL_L64 = 50
137 OP_MUL_H64 = 51
138 OP_MUL_H32 = 52
139 OP_OR = 53
140 OP_POPCNT = 54
141 OP_PRTY = 55
142 OP_RLC = 56
143 OP_RLCL = 57
144 OP_RLCR = 58
145 OP_SETB = 59
146 OP_SHL = 60
147 OP_SHR = 61
148 OP_SYNC = 62
149 OP_TD = 63
150 OP_TDI = 64
151 OP_TW = 65
152 OP_TWI = 66
153 OP_XOR = 67
154 OP_SIM_CONFIG = 68
155
156
157 @unique
158 class In1Sel(Enum):
159 NONE = 0
160 RA = 1
161 RA_OR_ZERO = 2
162 SPR = 3
163
164
165 @unique
166 class In2Sel(Enum):
167 NONE = 0
168 RB = 1
169 CONST_UI = 2
170 CONST_SI = 3
171 CONST_UI_HI = 4
172 CONST_SI_HI = 5
173 CONST_LI = 6
174 CONST_BD = 7
175 CONST_DS = 8
176 CONST_M1 = 9
177 CONST_SH = 10
178 CONST_SH32 = 11
179 SPR = 12
180
181
182 @unique
183 class In3Sel(Enum):
184 NONE = 0
185 RS = 1
186
187
188 @unique
189 class OutSel(Enum):
190 NONE = 0
191 RT = 1
192 RA = 2
193 SPR = 3
194
195
196 @unique
197 class LdstLen(Enum):
198 NONE = 0
199 is1B = 1
200 is2B = 2
201 is4B = 3
202 is8B = 4
203
204
205 @unique
206 class RC(Enum):
207 NONE = 0
208 ONE = 1
209 RC = 2
210
211
212 @unique
213 class CryIn(Enum):
214 ZERO = 0
215 ONE = 1
216 CA = 2
217
218
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
222
223 spr_csv = get_csv("sprs.csv")
224 fields = [(row['SPR'], int(row['Idx'])) for row in spr_csv]
225 SPR = Enum('SPR', fields)