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