From 0a8ce0593afad81156b947282c8c381737467379 Mon Sep 17 00:00:00 2001 From: bbracker Date: Wed, 6 Apr 2022 07:49:44 -0700 Subject: [PATCH] filter traps list down to just interrupts --- .../filterTrapsToInterrupts.py | 68 +++++++++++++++++++ linux/testvector-generation/genTrace.sh | 7 +- 2 files changed, 74 insertions(+), 1 deletion(-) create mode 100755 linux/testvector-generation/filterTrapsToInterrupts.py diff --git a/linux/testvector-generation/filterTrapsToInterrupts.py b/linux/testvector-generation/filterTrapsToInterrupts.py new file mode 100755 index 00000000..de055309 --- /dev/null +++ b/linux/testvector-generation/filterTrapsToInterrupts.py @@ -0,0 +1,68 @@ +#! /usr/bin/python3 +import sys, os +from functools import reduce + +################ +# Helper Funcs # +################ + +def tokenize(string): + tokens = [] + token = '' + whitespace = 0 + prevWhitespace = 0 + for char in string: + prevWhitespace = whitespace + whitespace = char in ' \t\n' + if (whitespace): + if ((not prevWhitespace) and (token != '')): + tokens.append(token) + token = '' + else: + token = token + char + return tokens + +def strip0x(num): + return num[2:] + +def stripZeroes(num): + num = num.strip('0') + if num=='': + return '0' + else: + return num + +############# +# Main Code # +############# +print("Begin filtering traps down to just external interrupts.") + +# Parse Args +if len(sys.argv) != 2: + sys.exit('Error filterTrapsToInterrupts.py expects 1 arg: ') +tvDir = sys.argv[1]+'/' +trapsFilePath = tvDir+'traps.txt' +if not os.path.exists(trapsFilePath): + sys.exit('Error input file '+trapsFilePath+'not found') + +with open(tvDir+'interrupts.txt', 'w') as interruptsFile: + with open(trapsFilePath, 'r') as trapsFile: + while True: + trap = trapsFile.readline() + if trap == '': + break + trapType = trap.split(' ')[-1] + if ('interrupt' in trap) and (('external' in trapType) or ('m_timer' in trapType)): # no s_timer because that is not controlled by CLINT + interruptsFile.write(trap) # overall line + interruptsFile.write(trapsFile.readline()) # attempted instr count + interruptsFile.write(trapsFile.readline()) # hart # + interruptsFile.write(trapsFile.readline()) # asynchronous + interruptsFile.write(trapsFile.readline()) # cause + interruptsFile.write(trapsFile.readline()) # epc + interruptsFile.write(trapsFile.readline()) # tval + interruptsFile.write(trapsFile.readline()) # description + else: + for i in range(7): + trapsFile.readline() + +print("Finished filtering traps down to just external interrupts.") diff --git a/linux/testvector-generation/genTrace.sh b/linux/testvector-generation/genTrace.sh index 5c79ee3d..df540c53 100755 --- a/linux/testvector-generation/genTrace.sh +++ b/linux/testvector-generation/genTrace.sh @@ -4,10 +4,12 @@ imageDir=$RISCV/buildroot/output/images tvDir=$RISCV/linux-testvectors recordFile="$tvDir/all.qemu" traceFile="$tvDir/all.txt" +trapsFile="$tvDir/traps.txt" interruptsFile="$tvDir/interrupts.txt" read -p "Warning: running this script will overwrite the contents of: * $traceFile + * $trapsFile * $interruptsFile Would you like to proceed? (y/n) " -n 1 -r echo @@ -28,6 +30,7 @@ then fi touch $traceFile + touch $trapsFile touch $interruptsFile # QEMU Simulation @@ -38,7 +41,9 @@ then -bios $imageDir/fw_jump.elf -kernel $imageDir/Image -append "root=/dev/vda ro" -initrd $imageDir/rootfs.cpio \ -singlestep -rtc clock=vm -icount shift=0,align=off,sleep=on,rr=replay,rrfile=$recordFile \ -d nochain,cpu,in_asm,int \ - 2>&1 >./qemu-serial | ./parseQEMUtoGDB.py | ./parseGDBtoTrace.py $interruptsFile | ./remove_dup.awk > $traceFile) + 2>&1 >./qemu-serial | ./parseQEMUtoGDB.py | ./parseGDBtoTrace.py $trapsFile | ./remove_dup.awk > $traceFile) + + ./filterTrapsToInterrupts.py $tvDir echo "genTrace.sh completed!" echo "You may want to restrict write access to $tvDir now and give cad ownership of it."