add MFMSR and MTMSRD enums to Function
[soc.git] / src / soc / decoder / power_enums.py
1 from enum import Enum, unique
2 import csv
3 import os
4 from os.path import dirname, join
5 from collections import namedtuple
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 = ['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 'CR in': 'NONE',
34 'ldst len': 'NONE',
35 'rc': 'NONE', 'cry in': 'ZERO', 'form': 'NONE'}
36
37
38 def get_signal_name(name):
39 if name[0].isdigit():
40 name = "is_" + name
41 return name.lower().replace(' ', '_')
42
43 # this corresponds to which Function Unit (pipeline-with-Reservation-Stations)
44 # is to process and guard the operation. they are roughly divided by having
45 # the same register input/output signature (X-Form, etc.)
46 @unique
47 class Function(Enum):
48 NONE = 0
49 ALU = 1
50 LDST = 2
51 SHIFT_ROT = 3
52 LOGICAL = 4
53 BRANCH = 5
54 CR = 6
55 TRAP = 7
56 MUL = 8
57 DIV = 9
58
59
60 @unique
61 class Form(Enum):
62 NONE = 0
63 I = 1
64 B = 2
65 SC = 3
66 D = 4
67 DS = 5
68 DQ = 6
69 DX = 7
70 X = 8
71 XL = 9
72 XFX = 10
73 XFL = 11
74 XX1 = 12
75 XX2 = 13
76 XX3 = 14
77 XX4 = 15
78 XS = 16
79 XO = 17
80 A = 18
81 M = 19
82 MD = 20
83 MDS = 21
84 VA = 22
85 VC = 23
86 VX = 24
87 EVX = 25
88 EVS = 26
89 Z22 = 27
90 Z23 = 28
91
92
93 # Internal Operation numbering. Add new opcodes here (FPADD, FPMUL etc.)
94 @unique
95 class InternalOp(Enum):
96 OP_ILLEGAL = 0 # important that this is zero (see power_decoder.py)
97 OP_NOP = 1
98 OP_ADD = 2
99 OP_ADDPCIS = 3
100 OP_AND = 4
101 OP_ATTN = 5
102 OP_B = 6
103 OP_BC = 7
104 OP_BCREG = 8
105 OP_BPERM = 9
106 OP_CMP = 10
107 OP_CMPB = 11
108 OP_CMPEQB = 12
109 OP_CMPRB = 13
110 OP_CNTZ = 14
111 OP_CRAND = 15
112 OP_CRANDC = 16
113 OP_CREQV = 17
114 OP_CRNAND = 18
115 OP_CRNOR = 19
116 OP_CROR = 20
117 OP_CRORC = 21
118 OP_CRXOR = 22
119 OP_DARN = 23
120 OP_DCBF = 24
121 OP_DCBST = 25
122 OP_DCBT = 26
123 OP_DCBTST = 27
124 OP_DCBZ = 28
125 OP_DIV = 29
126 OP_DIVE = 30
127 OP_EXTS = 31
128 OP_EXTSWSLI = 32
129 OP_ICBI = 33
130 OP_ICBT = 34
131 OP_ISEL = 35
132 OP_ISYNC = 36
133 OP_LOAD = 37
134 OP_STORE = 38
135 OP_MADDHD = 39
136 OP_MADDHDU = 40
137 OP_MADDLD = 41
138 OP_MCRF = 42
139 OP_MCRXR = 43
140 OP_MCRXRX = 44
141 OP_MFCR = 45
142 OP_MFSPR = 46
143 OP_MOD = 47
144 OP_MTCRF = 48
145 OP_MTSPR = 49
146 OP_MUL_L64 = 50
147 OP_MUL_H64 = 51
148 OP_MUL_H32 = 52
149 OP_OR = 53
150 OP_POPCNT = 54
151 OP_PRTY = 55
152 OP_RLC = 56
153 OP_RLCL = 57
154 OP_RLCR = 58
155 OP_SETB = 59
156 OP_SHL = 60
157 OP_SHR = 61
158 OP_SYNC = 62
159 OP_TRAP = 63
160 OP_XOR = 67
161 OP_SIM_CONFIG = 68
162 OP_CROP = 69
163 OP_RFID = 70
164 OP_MFMSR = 71
165 OP_MTMSRD = 72
166
167
168 @unique
169 class In1Sel(Enum):
170 NONE = 0
171 RA = 1
172 RA_OR_ZERO = 2
173 SPR = 3
174
175
176 @unique
177 class In2Sel(Enum):
178 NONE = 0
179 RB = 1
180 CONST_UI = 2
181 CONST_SI = 3
182 CONST_UI_HI = 4
183 CONST_SI_HI = 5
184 CONST_LI = 6
185 CONST_BD = 7
186 CONST_DS = 8
187 CONST_M1 = 9
188 CONST_SH = 10
189 CONST_SH32 = 11
190 SPR = 12
191
192
193 @unique
194 class In3Sel(Enum):
195 NONE = 0
196 RS = 1
197
198
199 @unique
200 class OutSel(Enum):
201 NONE = 0
202 RT = 1
203 RA = 2
204 SPR = 3
205
206
207 @unique
208 class LdstLen(Enum):
209 NONE = 0
210 is1B = 1
211 is2B = 2
212 is4B = 3
213 is8B = 4
214
215
216 @unique
217 class RC(Enum):
218 NONE = 0
219 ONE = 1
220 RC = 2
221
222
223 @unique
224 class CryIn(Enum):
225 ZERO = 0
226 ONE = 1
227 CA = 2
228
229 @unique
230 class CRInSel(Enum):
231 NONE = 0
232 CR0 = 1
233 BI = 2
234 BFA = 3
235 BA_BB = 4
236 BC = 5
237 WHOLE_REG = 6
238
239 @unique
240 class CROutSel(Enum):
241 NONE = 0
242 CR0 = 1
243 BF = 2
244 BT = 3
245 WHOLE_REG = 4
246
247
248 # SPRs - Special-Purpose Registers. See V3.0B Figure 18 p971 and
249 # http://libre-riscv.org/openpower/isatables/sprs.csv
250 # http://bugs.libre-riscv.org/show_bug.cgi?id=261
251
252 spr_csv = get_csv("sprs.csv")
253 spr_info = namedtuple('spr_info', 'SPR priv_mtspr priv_mfspr length')
254 spr_dict = {}
255 for row in spr_csv:
256 info = spr_info(SPR=row['SPR'], priv_mtspr=row['priv_mtspr'],
257 priv_mfspr=row['priv_mfspr'], length=int(row['len']))
258 spr_dict[int(row['Idx'])] = info
259 fields = [(row['SPR'], int(row['Idx'])) for row in spr_csv]
260 SPR = Enum('SPR', fields)
261
262
263 XER_bits = {
264 'SO': 32,
265 'OV': 33,
266 'CA': 34,
267 'OV32': 44,
268 'CA32': 45
269 }