move all source directories to soc so that "import soc.scoreboard" etc is used
[soc.git] / src / soc / decoder / power_enums.py
1 from enum import Enum, unique
2 import csv
3 import os
4 import requests
5
6
7 def get_csv(name):
8 file_dir = os.path.dirname(os.path.realpath(__file__))
9 file_path = os.path.join(file_dir, name)
10 if not os.path.isfile(file_path):
11 url = 'https://libre-riscv.org/openpower/isatables/' + name
12 r = requests.get(url, allow_redirects=True)
13 with open(file_path, 'w') as outfile:
14 outfile.write(r.content.decode("utf-8"))
15 with open(file_path, 'r') as csvfile:
16 reader = csv.DictReader(csvfile)
17 return list(reader)
18
19
20 # names of the fields in the tables that don't correspond to an enum
21 single_bit_flags = ['CR in', 'CR out', 'inv A', 'inv out',
22 'cry out', 'BR', 'sgn ext', 'upd', 'rsrv', '32b',
23 'sgn', 'lk', 'sgl pipe']
24
25 # default values for fields in the table
26 default_values = {'unit': "NONE", 'internal op': "OP_ILLEGAL",
27 'in1': "RA", 'in2': 'NONE', 'in3': 'NONE', 'out': 'NONE',
28 'ldst len': 'NONE',
29 'rc' : 'NONE', 'cry in' : 'ZERO', 'form': 'NONE'}
30
31 def get_signal_name(name):
32 if name[0].isdigit():
33 name = "is_" + name
34 return name.lower().replace(' ', '_')
35
36
37 @unique
38 class Function(Enum):
39 NONE = 0
40 ALU = 1
41 LDST = 2
42
43
44 @unique
45 class Form(Enum):
46 NONE = 0
47 I = 1
48 B = 2
49 SC = 3
50 D = 4
51 DS = 5
52 DQ = 6
53 DX = 7
54 X = 8
55 XL = 9
56 XFX = 10
57 XFL = 11
58 XX1 = 12
59 XX2 = 13
60 XX3 = 14
61 XX4 = 15
62 XS = 16
63 XO = 17
64 A = 18
65 M = 19
66 MD = 20
67 MDS = 21
68 VA = 22
69 VC = 23
70 VX = 24
71 EVX = 25
72 EVS = 26
73 Z22 = 27
74 Z23 = 28
75
76
77
78 @unique
79 class InternalOp(Enum):
80 OP_ILLEGAL = 0
81 OP_NOP = 1
82 OP_ADD = 2
83 OP_ADDPCIS = 3
84 OP_AND = 4
85 OP_ATTN = 5
86 OP_B = 6
87 OP_BC = 7
88 OP_BCREG = 8
89 OP_BPERM = 9
90 OP_CMP = 10
91 OP_CMPB = 11
92 OP_CMPEQB = 12
93 OP_CMPRB = 13
94 OP_CNTZ = 14
95 OP_CRAND = 15
96 OP_CRANDC = 16
97 OP_CREQV = 17
98 OP_CRNAND = 18
99 OP_CRNOR = 19
100 OP_CROR = 20
101 OP_CRORC = 21
102 OP_CRXOR = 22
103 OP_DARN = 23
104 OP_DCBF = 24
105 OP_DCBST = 25
106 OP_DCBT = 26
107 OP_DCBTST = 27
108 OP_DCBZ = 28
109 OP_DIV = 29
110 OP_DIVE = 30
111 OP_EXTS = 31
112 OP_EXTSWSLI = 32
113 OP_ICBI = 33
114 OP_ICBT = 34
115 OP_ISEL = 35
116 OP_ISYNC = 36
117 OP_LOAD = 37
118 OP_STORE = 38
119 OP_MADDHD = 39
120 OP_MADDHDU = 40
121 OP_MADDLD = 41
122 OP_MCRF = 42
123 OP_MCRXR = 43
124 OP_MCRXRX = 44
125 OP_MFCR = 45
126 OP_MFSPR = 46
127 OP_MOD = 47
128 OP_MTCRF = 48
129 OP_MTSPR = 49
130 OP_MUL_L64 = 50
131 OP_MUL_H64 = 51
132 OP_MUL_H32 = 52
133 OP_OR = 53
134 OP_POPCNT = 54
135 OP_PRTY = 55
136 OP_RLC = 56
137 OP_RLCL = 57
138 OP_RLCR = 58
139 OP_SETB = 59
140 OP_SHL = 60
141 OP_SHR = 61
142 OP_SYNC = 62
143 OP_TD = 63
144 OP_TDI = 64
145 OP_TW = 65
146 OP_TWI = 66
147 OP_XOR = 67
148 OP_SIM_CONFIG = 68
149
150
151 @unique
152 class In1Sel(Enum):
153 RA = 0
154 RA_OR_ZERO = 1
155 NONE = 2
156 SPR = 3
157
158
159 @unique
160 class In2Sel(Enum):
161 NONE = 0
162 RB = 1
163 CONST_UI = 2
164 CONST_SI = 3
165 CONST_UI_HI = 4
166 CONST_SI_HI = 5
167 CONST_LI = 6
168 CONST_BD = 7
169 CONST_DS = 8
170 CONST_M1 = 9
171 CONST_SH = 10
172 CONST_SH32 = 11
173 SPR = 12
174
175
176 @unique
177 class In3Sel(Enum):
178 NONE = 0
179 RS = 1
180
181
182 @unique
183 class OutSel(Enum):
184 NONE = 0
185 RT = 1
186 RA = 2
187 SPR = 3
188
189
190 @unique
191 class LdstLen(Enum):
192 NONE = 0
193 is1B = 1
194 is2B = 2
195 is4B = 3
196 is8B = 4
197
198
199 @unique
200 class RC(Enum):
201 NONE = 0
202 ONE = 1
203 RC = 2
204
205
206 @unique
207 class CryIn(Enum):
208 ZERO = 0
209 ONE = 1
210 CA = 2
211
212 @unique
213 class SPR(Enum):
214 XER = 1
215 LR = 8
216 CTR = 9
217 TB = 268
218 SRR0 = 26
219 SRR1 = 27
220 HSRR0 = 314
221 HSRR1 = 315
222 SPRG0 = 272
223 SPRG1 = 273
224 SPRG2 = 274
225 SPRG3 = 275
226 SPRG3U = 259
227 HSPRG0 = 304
228 HSPRG1 = 305
229