Skip to content

Commit e8e1703

Browse files
authored
Merge pull request #76 from riscv-software-src/warl-fix-and-svnapot-support
clean up warl and svnapot support added
2 parents 8c01729 + 2347731 commit e8e1703

File tree

6 files changed

+38
-39
lines changed

6 files changed

+38
-39
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,4 @@ __pycache__/*
1010
*.pyc
1111

1212
riscv_config_work/*
13+
.python-version

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@
22

33
This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
44

5+
## [2.13.0] - 2022-03-09
6+
- add support for detection of svnapot in ISA string
7+
- genralize conversion of hex, oct, bin values to int in warl functions
8+
- machine flat schema to include wlrl types as well
9+
510
## [2.12.1] - 2021-12-18
611
### Fixed
712

riscv_config/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
from pkgutil import extend_path
22
__path__ = extend_path(__path__, __name__)
3-
__version__ = '2.12.1'
3+
__version__ = '2.13.0'

riscv_config/schemaValidator.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -72,17 +72,19 @@ def _check_with_capture_isa_specifics(self, field, value):
7272
else:
7373
self._error(field, "Invalid width in ISA.")
7474
#ISA checks
75-
str_match = re.findall(r'([^\d]*?)(?!_)*(Z.*?)*(_|$)',value,re.M)
75+
str_match = re.findall('(?P<stdisa>[^\d]*?)(?!_)*(?P<zext>Z.*?)*(?P<sext>S[a-z]*)*(_|$)',value)
7676
extension_list= []
7777
standard_isa = ''
7878
for match in str_match:
79-
stdisa, z, ignore = match
79+
stdisa, zext, sext, ignore = match
8080
if stdisa != '':
8181
for e in stdisa:
8282
extension_list.append(e)
8383
standard_isa = stdisa
84-
if z != '':
85-
extension_list.append(z)
84+
if zext != '':
85+
extension_list.append(zext)
86+
if sext != '':
87+
extension_list.append(sext)
8688
# check ordering of ISA
8789
canonical_ordering = 'IEMAFDQLCBJKTPVNSHU'
8890
order_index = {c: i for i, c in enumerate(canonical_ordering)}

riscv_config/schemas/schema_isa.yaml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ hart_schema:
5757
# - The ISA string must be specified as per the convention mentioned in the specifications(like subsequent Z extensions must be separated with an '_')
5858

5959
ISA: { type: string, required: true, check_with: capture_isa_specifics,
60-
regex: "^RV(32|64|128)[IE]+[ABCDEFGHJKLMNPQSTUVX]*(Zicsr|Zifencei|Zihintpause|Zam|Ztso|Zkne|Zknd|Zknh|Zkse|Zksh|Zkg|Zkb|Zkr|Zks|Zkn|Zba|Zbc|Zbb|Zbp|Zbr|Zbm|Zbs|Zbe|Zbf|Zbt|Zmmul){,1}(_Zicsr){,1}(_Zifencei){,1}(_Zihintpause){,1}(_Zmmul){,1}(_Zam){,1}(_Zba){,1}(_Zbb){,1}(_Zbc){,1}(_Zbe){,1}(_Zbf){,1}(_Zbm){,1}(_Zbp){,1}(_Zbr){,1}(_Zbs){,1}(_Zbt){,1}(_Zkb){,1}(_Zkg){,1}(_Zkr){,1}(_Zks){,1}(_Zkn){,1}(_Zknd){,1}(_Zkne){,1}(_Zknh){,1}(_Zkse){,1}(_Zksh){,1}(_Ztso){,1}$" }
60+
regex: "^RV(32|64|128)[IE]+[ABCDEFGHJKLMNPQSTUVX]*(Zicsr|Zifencei|Zihintpause|Zam|Ztso|Zkne|Zknd|Zknh|Zkse|Zksh|Zkg|Zkb|Zkr|Zks|Zkn|Zba|Zbc|Zbb|Zbp|Zbr|Zbm|Zbs|Zbe|Zbf|Zbt|Zmmul|Svnapot){,1}(_Zicsr){,1}(_Zifencei){,1}(_Zihintpause){,1}(_Zmmul){,1}(_Zam){,1}(_Zba){,1}(_Zbb){,1}(_Zbc){,1}(_Zbe){,1}(_Zbf){,1}(_Zbm){,1}(_Zbp){,1}(_Zbr){,1}(_Zbs){,1}(_Zbt){,1}(_Zkb){,1}(_Zkg){,1}(_Zkr){,1}(_Zks){,1}(_Zkn){,1}(_Zknd){,1}(_Zkne){,1}(_Zknh){,1}(_Zkse){,1}(_Zksh){,1}(_Ztso){,1}(_Svnapot){,1}$" }
6161

6262
###
6363
#User_Spec_Version
@@ -295,6 +295,7 @@ hart_schema:
295295
oneof:
296296
- schema: {ro_constant: {type: integer, max: 0xFFFFFFFF}}
297297
- schema: { warl: *ref_warl }
298+
- schema: { wlrl: *ref_wlrl }
298299
default:
299300
ro_constant: 0
300301
accessible:
@@ -316,6 +317,7 @@ hart_schema:
316317
oneof:
317318
- schema: {ro_constant: {type: integer, max: 0xFFFFFFFFFFFFFFFF}}
318319
- schema: { warl: *ref_warl }
320+
- schema: { wlrl: *ref_wlrl }
319321
default:
320322
ro_constant: 0
321323
accessible:

riscv_config/warl.py

Lines changed: 22 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ def prevsum(self, i, k):
2626

2727
def islegal(self, value, dependency_vals=[]):
2828
is_legal = False
29-
logger.debug('Checking for isLegal for WARL: \n\t' +
29+
logger.debug('Checking for isLegal for WARL: \n' +
3030
utils.pretty_print_yaml(self.warl) + '\n With following args:'\
3131
+ 'val : ' + str(value) + ' dep_vals :'+
3232
str(dependency_vals))
@@ -46,21 +46,15 @@ def islegal(self, value, dependency_vals=[]):
4646
if not bitmask: # if its not a bitmask
4747
if ":" in csr_vals: # range is specified
4848
[base, bound] = csr_vals.split(':')
49-
if 'x' in base:
50-
base = int(base,16)
51-
else:
52-
base = int(base,10)
53-
if 'x' in bound:
54-
bound = int(bound,16)
55-
else:
56-
bound = int(bound,10)
49+
base = int(base, 0)
50+
bound = int(bound, 0)
5751
if value >= base and value <= bound: # check legal range
5852
part_legal = True
5953
else:
6054
l_vals = csr_vals.split(',')
6155
legal_vals = []
6256
for i in l_vals :
63-
legal_vals.append(int(i,16))
57+
legal_vals.append(int(i,0))
6458
if value in legal_vals:
6559
part_legal = True
6660
else: # in case of bitmask there are no illegal values
@@ -100,17 +94,15 @@ def islegal(self, value, dependency_vals=[]):
10094
# check if the dependency value is satisfied.
10195
if ":" in dep_vals: # range is specified
10296
[base, bound] = dep_vals.split(':')
103-
if 'x' in base:
104-
base = int(base,16)
105-
if 'x' in bound:
106-
bound = int(bound,16)
97+
base = int(base, 0)
98+
bound = int(bound, 0)
10799
if recvd_val >= base and recvd_val <= bound: # check legal range
108100
dep_satified = True
109101
else:
110102
l_vals = dep_vals.split(',')
111103
legal_vals = []
112104
for i in l_vals :
113-
legal_vals.append(int(i,16))
105+
legal_vals.append(int(i,0))
114106
if recvd_val in legal_vals:
115107
dep_satified = True
116108

@@ -125,17 +117,15 @@ def islegal(self, value, dependency_vals=[]):
125117
if not bitmask: # if its not a bitmask
126118
if ":" in csr_vals: # range is specified
127119
[base, bound] = csr_vals.split(':')
128-
if 'x' in base:
129-
base = int(base,16)
130-
if 'x' in bound:
131-
bound = int(bound,16)
120+
base = int(base, 0)
121+
bound = int(bound, 0)
132122
if trunc_val >= base and trunc_val <= bound: # check legal range
133123
part_legal = True
134124
else:
135125
l_vals = csr_vals.split(',')
136126
legal_vals = []
137127
for i in l_vals :
138-
legal_vals.append(int(i,16))
128+
legal_vals.append(int(i,0))
139129
if trunc_val in legal_vals:
140130
part_legal = True
141131
else: # in case of bitmask there are no illegal values
@@ -196,9 +186,8 @@ def update(self, curr_val, wr_val, dependency_vals=[]):
196186
for i1 in range(len(dependency_vals)):
197187
if dependency_vals[i1] == int(mode[i1]):
198188
if op != []:
199-
if int(wr_val,
200-
16) in range(int(z[0], 16),
201-
int(z[1], 16)):
189+
if int(wr_val, 0) in range(int(z[0], 0),
190+
int(z[1], 0)):
202191
j = i
203192
flag1 = 1
204193
break
@@ -220,7 +209,7 @@ def update(self, curr_val, wr_val, dependency_vals=[]):
220209
self.warl['wr_illegal'][i])
221210
if op != []:
222211
z = re.split("\:", op[0])
223-
if int(wr_val, 16) in range(int(z[0], 16), int(z[1], 16)):
212+
if int(wr_val, 0) in range(int(z[0], 0), int(z[1], 0)):
224213
j = i
225214
flag1 = 1
226215
break
@@ -260,7 +249,7 @@ def update(self, curr_val, wr_val, dependency_vals=[]):
260249
l = self.legal(dependency_vals)
261250
for i in range(len(l)):
262251
if len(l[i]) == 1:
263-
a.append(abs(int(wr_val, 16) - int(l[i][0], 16)))
252+
a.append(abs(int(wr_val, 0) - int(l[i][0], 0)))
264253
for i in range(len(a) - 1, -1, -1):
265254
if a[i] == min(a):
266255
j = i
@@ -274,7 +263,7 @@ def update(self, curr_val, wr_val, dependency_vals=[]):
274263
l = self.legal(dependency_vals)
275264
for i in range(len(l)):
276265
if len(l[i]) == 1:
277-
a.append(abs(int(wr_val, 16) - int(l[i][0], 16)))
266+
a.append(abs(int(wr_val, 0) - int(l[i][0], 0)))
278267
for i in range(len(a)):
279268
if a[i] == min(a):
280269
j = i
@@ -286,7 +275,7 @@ def update(self, curr_val, wr_val, dependency_vals=[]):
286275
elif wr.lower().strip() == "nextup":
287276
l = self.legal(dependency_vals)
288277
for i in range(len(l)):
289-
if int(l[i][0], 16) > int(wr_val, 16) and len(l[i]) == 1:
278+
if int(l[i][0], 0) > int(wr_val, 0) and len(l[i]) == 1:
290279
j = i
291280
flag2 = 1
292281
break
@@ -298,7 +287,7 @@ def update(self, curr_val, wr_val, dependency_vals=[]):
298287
elif wr.lower().strip() == "nextdown":
299288
l = self.legal(dependency_vals)
300289
for i in range(len(l)):
301-
if int(l[i][0], 16) > int(wr_val, 16) and len(l[i]) == 1:
290+
if int(l[i][0], 0) > int(wr_val, 0) and len(l[i]) == 1:
302291
j = i
303292
flag2 = 1
304293
break
@@ -338,7 +327,7 @@ def update(self, curr_val, wr_val, dependency_vals=[]):
338327
return y[0]
339328

340329
elif wr.lower().strip() == "addr":
341-
wr = format(int(wr_val, 16),
330+
wr = format(int(wr_val, 0),
342331
'#0{}b'.format(4 * self.bitsum + 2))
343332
wr = wr[2:]
344333
if wr[0:1] == '0':
@@ -347,7 +336,7 @@ def update(self, curr_val, wr_val, dependency_vals=[]):
347336
wr_final = '0' + wr[1:]
348337
else:
349338
print("Invalid binary bit")
350-
return hex(int(wr_final, 2))
339+
return hex(int(wr_final, 0))
351340

352341
else:
353342
return "Invalid update mode"
@@ -358,9 +347,9 @@ def update(self, curr_val, wr_val, dependency_vals=[]):
358347
z = re.findall(
359348
r'\s*.*\s*\[(.*)\]\s*{}\s*\[.*?,.*?\]'.format("bitmask"), inp1)
360349
y = re.split("\,", x[0])
361-
bitmask = int(y[0], 16)
362-
fixedval = int(y[1], 16)
363-
currval = int(wr_val, 16)
350+
bitmask = int(y[0], 0)
351+
fixedval = int(y[1], 0)
352+
currval = int(wr_val, 0)
364353
legal = ((currval & bitmask) | fixedval)
365354
return hex(legal)
366355

0 commit comments

Comments
 (0)