1
0
mirror of https://github.com/aolofsson/oh.git synced 2025-02-07 06:44:09 +08:00

Rewritten trace script for spike

-ovpsim is a dead end, good bye
This commit is contained in:
Andreas.Olofsson 2020-03-28 15:37:10 -04:00
parent cbb8f79fd2
commit 65aa1b061c

View File

@ -2,24 +2,24 @@
############################################################################# #############################################################################
# trace2trace <inputfile> <outputfile> # trace2trace <inputfile> <outputfile>
# #
# Converts a simulation trace file to the epiphany trace format # Converts a simulator trace file to the epiphany trace format
# #
# Simulators supported: ovpsim, spike # Formats: spike, cgen
# #
############################################################################# #############################################################################
import re import re
import sys import sys
simulator="spike"
offset=0xffffffff00000000
#Input Arguments #Input Arguments
with open(sys.argv[1], 'r') as f: with open(sys.argv[1], 'r') as f:
file_content = f.read() file_content = f.read()
fileout=open(sys.argv[2],"w") fileout=open(sys.argv[2],"w")
#Reading input file into buffer #RISC-V ABI dictionary
list=file_content.split('\'riscvOVPsim/cpu\'')
#ABI dictionary
regs={ regs={
"zero":"r0", "zero":"r0",
"ra":"r1", "ra":"r1",
@ -61,26 +61,52 @@ regs={
"mcause":"mcause", "mcause":"mcause",
} }
#Format Trace
#Reading input file into buffer
if(simulator=="spike") :
trap=0
list=file_content.split('core 0: ') #split based on core 0
for i in list: for i in list:
instr=i.replace('\n',' ') #replace all newlines in middle of strings i=re.sub(r'\n', ' ', i) #combine lines
instr=instr.replace('Info','') #remove info i=re.sub(r'x (\d{1})',r'x\1', i) #fix brain dead spike print for regs
instr=re.sub('\(SIGNATURE_DUMP.*','',instr) #remove crud from end of file i=re.sub(r'^0x0000000000001(.*)',r'', i) #remove spike boot rom
if(re.search('^\,',instr)) : #filter out more crud if(bool(re.search('trap_user_ecall',i))):#filter out everything after ecall
fields=instr.split() #split into fields trap=1
pc=re.sub('\(.*','',fields[1]) #filter empty instructions
pc=re.sub('0x','',pc) #removing hex prefix if((bool(re.search('0x',i))) & (trap==0)):
opcode=fields[2] fields=i.split()
name=fields[3].rjust(8) pc=int(fields[0],16)
if(re.search('\-\>',instr)) : opcode=fields[1]
#print("XXX" + instr) asm=fields[2]
reg=fields[-4] #for j in fields:
reg=regs[reg] # print (j)
val=fields[-1] if(re.search('0x',fields[-2])):
if(re.search('^r',reg)) : memaddr="--"
update=reg + "=" + val.zfill(16); #don't update csrs for now memdata="--"
reg="--"
regdata="--"
elif(re.search('mem',i)):
memaddr=fields[-2]
memdata=fields[-1]
reg="--"
regdata="--"
else: else:
update="" reg="x{0:02}".format(int(re.sub(r'x',r'', fields[-2])))
fileout.write("TRACE: cpu_0.trace PC=" + pc + " I=" + name + " F=-------- " + update + "\n") regdata=fields[-1]
memaddr="--"
memdata="--"
#Remove offsets
if(pc>=offset):
pc=pc-offset
#List of entires
flist=["0x{0:08x}".format(pc),
opcode,
"{:<8}".format(asm),
"{:<3}".format(reg),
"{:<10}".format(regdata),
"{:<10}".format(memaddr),
"{:<10}".format(memdata)]
outputstring=' , '.join(flist)
fileout.write(outputstring + "\n")
fileout.close() fileout.close()