From c38cbfac2c979580cd91e598ccb7173ea2bbabdd Mon Sep 17 00:00:00 2001 From: bacon Date: Thu, 27 Feb 2025 14:25:13 +0800 Subject: [PATCH] =?UTF-8?q?=E5=90=88=E5=B9=B6bacon=5Fdev=E5=88=86=E6=94=AF?= =?UTF-8?q?=E7=9A=84=E4=BF=AE=E6=94=B9:=E5=A2=9E=E5=8A=A0=E6=90=9C?= =?UTF-8?q?=E7=B4=A2=E8=87=AA=E5=AE=9A=E4=B9=89=E6=8C=87=E4=BB=A4=E7=9A=84?= =?UTF-8?q?python=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tb/sw/src/check_intflag.py | 56 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 tb/sw/src/check_intflag.py diff --git a/tb/sw/src/check_intflag.py b/tb/sw/src/check_intflag.py new file mode 100644 index 0000000..b44265a --- /dev/null +++ b/tb/sw/src/check_intflag.py @@ -0,0 +1,56 @@ +#!/usr/bin/python3 + +import os +import sys +import traceback +import re + + + +def search_custom_inst(logfile, opcode, funct, xd = 0, xs1 = 0, xs2 = 0, xd_filter = 0, xs1_filter = 0, xs2_filter = 0): + lines = logfile.readlines() + 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() + if (xs1 != 0) and ((rreg1_val & xs1_filter) != 0): + print(outline) + if (xd != 0) and ((wreg_val & xd_filter) != 0): + print(outline) + if (xs2 != 0) and ((rreg2_val & xs2_filter) != 0): + print(outline) + else: + pass + +if __name__ == '__main__': + path = sys.argv[0] + path = path.split('/')[0:-1] + path = '/'.join(path) + logfile_path = path + '/../build/cpu1_log.txt' + if len(sys.argv) > 1: + logfile_path = sys.argv[1] + print(logfile_path) + + with open(logfile_path, 'rt') as logfile: + search_custom_inst(logfile, 0xb, 0x17, xs1=1, xs1_filter=(1<<7)) + logfile.close()