2025-02-27 14:25:13 +08:00
|
|
|
#!/usr/bin/python3
|
|
|
|
|
|
|
|
|
|
import os
|
|
|
|
|
import sys
|
|
|
|
|
import traceback
|
|
|
|
|
import re
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2025-02-28 09:07:59 +08:00
|
|
|
def search_custom_inst(logdata, opcode, funct, xd = 0, xs1 = 0, xs2 = 0, xd_filter = 0, xs1_filter = 0, xs2_filter = 0):
|
|
|
|
|
lines = logdata
|
2025-02-27 14:25:13 +08:00
|
|
|
funct3 = 0
|
|
|
|
|
if xd != 0:
|
|
|
|
|
funct3 = funct3 | 0x4
|
|
|
|
|
if xs1 != 0:
|
|
|
|
|
funct3 = funct3 | 0x2
|
|
|
|
|
if xs2 != 0:
|
|
|
|
|
funct3 = funct3 | 0x1
|
|
|
|
|
|
|
|
|
|
for line in lines:
|
|
|
|
|
inst = re.findall(r"inst=\[[\da-fA-F]{8}\]", line)
|
|
|
|
|
wreg = re.findall(r"W\[r[\ \d]{2}=[\da-fA-F]{8}\]", line)
|
|
|
|
|
rreg = re.findall(r"R\[r[\ \d]{2}=[\da-fA-F]{8}\]", line)
|
|
|
|
|
if len(inst) > 0:
|
|
|
|
|
inst = int('0x' + inst[0][6:-1], 16)
|
|
|
|
|
wreg_val = int('0x' + wreg[0][6:-1], 16)
|
|
|
|
|
rreg1_val = int('0x' + rreg[0][6:-1], 16)
|
|
|
|
|
rreg2_val = int('0x' + rreg[1][6:-1], 16)
|
|
|
|
|
ins_opcode = inst & 0x7f
|
|
|
|
|
#只对R系列的custom0进行解码
|
|
|
|
|
if opcode == ins_opcode:
|
|
|
|
|
ins_funct = (inst >> 25) & 0x7f
|
|
|
|
|
ins_funct3 = (inst >> 12) & 0x7
|
|
|
|
|
if (ins_funct == funct) and (funct3 == ins_funct3):
|
|
|
|
|
outline = line.rstrip()
|
2025-02-28 09:07:59 +08:00
|
|
|
if (xs1 != 0) and ((rreg1_val & xs1_filter) == xs1_filter):
|
2025-02-27 14:25:13 +08:00
|
|
|
print(outline)
|
2025-02-28 09:07:59 +08:00
|
|
|
if (xd != 0) and ((wreg_val & xd_filter) == xd_filter):
|
2025-02-27 14:25:13 +08:00
|
|
|
print(outline)
|
2025-02-28 09:07:59 +08:00
|
|
|
if (xs2 != 0) and ((rreg2_val & xs2_filter) == xs2_filter):
|
2025-02-27 14:25:13 +08:00
|
|
|
print(outline)
|
|
|
|
|
else:
|
|
|
|
|
pass
|
|
|
|
|
|
2025-02-28 09:07:59 +08:00
|
|
|
|
|
|
|
|
def get_bit_pos(val):
|
|
|
|
|
bits_pos = list()
|
|
|
|
|
val = val & 0xffffffff
|
|
|
|
|
|
|
|
|
|
for i in range(32):
|
|
|
|
|
if (val & (1 << i)) != 0:
|
|
|
|
|
bits_pos.insert(0, i)
|
|
|
|
|
return bits_pos
|
|
|
|
|
|
2025-02-27 14:25:13 +08:00
|
|
|
if __name__ == '__main__':
|
|
|
|
|
path = sys.argv[0]
|
|
|
|
|
path = path.split('/')[0:-1]
|
|
|
|
|
path = '/'.join(path)
|
|
|
|
|
logfile_path = path + '/../build/cpu1_log.txt'
|
2025-02-28 09:07:59 +08:00
|
|
|
|
2025-02-27 14:25:13 +08:00
|
|
|
if len(sys.argv) > 1:
|
|
|
|
|
logfile_path = sys.argv[1]
|
|
|
|
|
print(logfile_path)
|
|
|
|
|
|
|
|
|
|
with open(logfile_path, 'rt') as logfile:
|
2025-02-28 09:07:59 +08:00
|
|
|
logdata = logfile.readlines()
|
|
|
|
|
|
|
|
|
|
filter = 1<<7
|
|
|
|
|
print(f'custom0-ins: clear roccs int flag, bit filter:', get_bit_pos(filter))
|
|
|
|
|
search_custom_inst(logdata, 0xb, 0x17, xs1=1, xs1_filter=filter)
|
|
|
|
|
|
|
|
|
|
'''
|
|
|
|
|
filter = (1<<10) | (1 << 7) | (1 << 2) | (1 << 1)
|
|
|
|
|
print('custom0-ins: clear roccs int flag, bit filter:', get_bit_pos(filter))
|
|
|
|
|
search_custom_inst(logdata, 0xb, 0x17, xs1=1, xs1_filter=filter)
|
|
|
|
|
'''
|
|
|
|
|
|
2025-02-27 14:25:13 +08:00
|
|
|
logfile.close()
|