summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGalen Williamson <galen@vector35.com>2025-07-30 19:01:32 -0400
committerGalen Williamson <galen@vector35.com>2025-08-14 14:06:49 -0400
commit408894062e4ff6b7271d7eaaf877d59be1712c74 (patch)
treeebcc0eb0359cf5058462332a16ee4c032571c53c
parentd6e13c753b30260b182cfe433e4e275244a4ab78 (diff)
[thumb2] Updated thumb2 disassembler generator to use Tatsu-generated parser instead of deprecated Grako
-rwxr-xr-xarch/armv7/thumb2_disasm/generator.py69
-rw-r--r--arch/armv7/thumb2_disasm/spec.cpp4
2 files changed, 39 insertions, 34 deletions
diff --git a/arch/armv7/thumb2_disasm/generator.py b/arch/armv7/thumb2_disasm/generator.py
index a027b74b..86a40fb7 100755
--- a/arch/armv7/thumb2_disasm/generator.py
+++ b/arch/armv7/thumb2_disasm/generator.py
@@ -448,8 +448,12 @@ class BitPattern:
maskNeg += 'x'*int(m.group(1))
elif re.match(r'^[\(\)01]+$', field):
# unpredictable fields (eg: "(0)(0)(0)(0)") are do-not-cares
- maskPos += 'x'*(len(field)/3)
- maskNeg += 'x'*(len(field)/3)
+ try:
+ maskPos += 'x'*(len(field)//3)
+ maskNeg += 'x'*(len(field)//3)
+ except:
+ print(f'stupid math in {field!r} in {self.text!r}')
+ raise
else:
parseError('genCheckMatch(): unknown bit extract field %s' % field)
@@ -459,7 +463,7 @@ class BitPattern:
# finally convert to a check
tmp = bitMaskGenCheckMatch(maskPos, varName)
- if filter(lambda a: a!='x', maskNeg):
+ if list(filter(lambda a: a!='x', maskNeg)):
tmp += ' && !'+bitMaskGenCheckMatch(maskNeg, varName)
return tmp
@@ -532,7 +536,7 @@ class BitPattern:
else:
m = re.match(r'^[\(\)01]+$', field)
if m:
- nBits = len(field)/3
+ nBits = len(field)//3
else:
parseError('genExtractGeneral(): unknown bit extract field %s' % field)
@@ -600,7 +604,7 @@ class BitPattern:
# get the width of a variable from within the pattern
def getVarWidth(self, varName):
- regex = varName + '\.(\\d)'
+ regex = varName + r'\.(\\d)'
#print("trying to get var: %s" % varName)
#print("using regex: %s" % regex)
@@ -673,7 +677,7 @@ def genEncodingBlock(mgr, encName, arches, fmts, pattern, pcode):
# generate architecture check
checks = []
for arch in arches.split(', '):
- checks.append('!(req->arch & ARCH_%s)' % string.replace(arch, '*', ''))
+ checks.append('!(req->arch & ARCH_%s)' % arch.replace('*', ''))
mgr.add("if(%s) {" % ' && '.join(checks))
mgr.tab()
mgr.add('res->status |= STATUS_ARCH_UNSUPPORTED;')
@@ -1323,9 +1327,9 @@ def gen_node(mgr, nodeName, lines):
checks.append(bitMaskGenCheckMatch(mask, varName))
# collapse all '1's into a single 1
- trues = filter(lambda x: x=='1', checks)
+ trues = list(filter(lambda x: x=='1', checks))
if trues:
- others = filter(lambda x: x!='1', checks)
+ others = list(filter(lambda x: x!='1', checks))
checks = others + ['1']
# and generate the code
@@ -1389,30 +1393,32 @@ if __name__ == '__main__':
for node in node2lines.keys():
node2crc[node] = binascii.crc32((''.join(node2lines[node])).encode('utf-8')) & 0xFFFFFFFF
- # open spec.cpp, read the crc's of generated functions (detecting if they need regen)
- print('collecting functions from spec.cpp')
- fp = open('spec.cpp', 'r')
- lines = fp.readlines()
- fp.close()
-
- lines = list(map(lambda x: x.rstrip(), lines))
+ forceGen = 'force' in sys.argv
funcInfo = {}
- i = 0
- while i < len(lines):
- m = re.match(r'^// gen_crc: (........).*', lines[i])
- if not m:
- i += 1
- continue
- crc = int(m.group(1), 16)
- m = re.match(r'^int ([\w\d]+)\(.*$', lines[i+1])
- if not m:
- raise Exception('did not find function after crc line %d: %s' % (i+1,lines[i]))
- name = m.group(1)
- start = i
- while lines[i] != '}':
- i += 1
- funcInfo[name] = {'crc':crc, 'lines':'\n'.join(lines[start:i+1])}
- #print('found that %s has crc %08X' % (name, crc))
+ if not forceGen and os.path.exists('spec.cpp'):
+ # open spec.cpp, read the crc's of generated functions (detecting if they need regen)
+ print('collecting functions from spec.cpp')
+ fp = open('spec.cpp', 'r')
+ lines = fp.readlines()
+ fp.close()
+
+ lines = list(map(lambda x: x.rstrip(), lines))
+ i = 0
+ while i < len(lines):
+ m = re.match(r'^// gen_crc: (........).*', lines[i])
+ if not m:
+ i += 1
+ continue
+ crc = int(m.group(1), 16)
+ m = re.match(r'^int ([\w\d]+)\(.*$', lines[i+1])
+ if not m:
+ raise Exception('did not find function after crc line %d: %s' % (i+1,lines[i]))
+ name = m.group(1)
+ start = i
+ while lines[i] != '}':
+ i += 1
+ funcInfo[name] = {'crc':crc, 'lines':'\n'.join(lines[start:i+1])}
+ #print('found that %s has crc %08X' % (name, crc))
# construct the new file
mgr = CodeManager()
@@ -1423,7 +1429,6 @@ if __name__ == '__main__':
mgr.add(support)
count = 0
- forceGen = 'force' in sys.argv
# for every node that doesn't have a matching function, generate!
for node in sorted(node2lines.keys()):
nodeCrc = node2crc[node]
diff --git a/arch/armv7/thumb2_disasm/spec.cpp b/arch/armv7/thumb2_disasm/spec.cpp
index f618eff7..38e14d02 100644
--- a/arch/armv7/thumb2_disasm/spec.cpp
+++ b/arch/armv7/thumb2_disasm/spec.cpp
@@ -34286,7 +34286,7 @@ int vcvt_float_fixed(struct decomp_request *req, struct decomp_result *res)
return undefined(req, res);
}
-// gen_crc: 3CB799A8
+// gen_crc: EBC7DA24
int vcvt_float_int(struct decomp_request *req, struct decomp_result *res)
{
int rc = -1;
@@ -34486,7 +34486,7 @@ int vcvt_float_int(struct decomp_request *req, struct decomp_result *res)
res->fields[FIELD_fmt_idx] = (((((((res->fields[FIELD_op]) == (0x0))) * (4))) + (((res->fields[FIELD_opc3]) * (2)))) + (res->fields[FIELD_sz])) + (2);
res->fields_mask[FIELD_fmt_idx >> 6] |= 1LL << (FIELD_fmt_idx & 63);
/* pcode: if (opc1 == '0') then fmt_idx = sz */
- if((res->fields[FIELD_opc1]) == 0x0) {
+ if(((res->fields[FIELD_opc1]) == (0x0))) {
res->fields[FIELD_fmt_idx] = res->fields[FIELD_sz];
res->fields_mask[FIELD_fmt_idx >> 6] |= 1LL << (FIELD_fmt_idx & 63);
}