aboutsummaryrefslogtreecommitdiffstats
path: root/showtrace.py
diff options
context:
space:
mode:
authorClifford Wolf <clifford@clifford.at>2016-08-25 14:15:42 +0200
committerClifford Wolf <clifford@clifford.at>2016-08-25 14:15:42 +0200
commit7094e61af7dfe3c24ff4218557b209a1b09e5793 (patch)
tree4906b7411df5594f68dda674a29bee2d6a28e82f /showtrace.py
parent8043c90a04031c1619d0be7b1aba717e4f9968ac (diff)
downloadpicorv32-7094e61af7dfe3c24ff4218557b209a1b09e5793.tar.gz
picorv32-7094e61af7dfe3c24ff4218557b209a1b09e5793.zip
Added tracer support (under construction)
Diffstat (limited to 'showtrace.py')
-rw-r--r--showtrace.py50
1 files changed, 50 insertions, 0 deletions
diff --git a/showtrace.py b/showtrace.py
new file mode 100644
index 0000000..56c91ff
--- /dev/null
+++ b/showtrace.py
@@ -0,0 +1,50 @@
+#!/usr/bin/env python3
+
+import sys, re, subprocess
+
+trace_filename = sys.argv[1]
+elf_filename = sys.argv[2]
+
+insns = dict()
+
+with subprocess.Popen(["riscv32-unknown-elf-objdump", "-d", elf_filename], stdout=subprocess.PIPE) as proc:
+ while True:
+ line = proc.stdout.readline().decode("ascii")
+ if line == '': break
+ match = re.match(r'^\s*([0-9a-f]+):\s+(\S+)\s*(.*)', line)
+ if match: insns[int(match.group(1), 16)] = (int(match.group(2), 16), match.group(3).replace("\t", " "))
+
+with open(trace_filename, "r") as f:
+ pc = -1
+ last_irq = False
+ for line in f:
+ raw_data = int(line.replace("x", "0"), 16)
+ payload = raw_data & 0xffffffff
+ irq_active = (raw_data & 0x800000000) != 0
+ is_addr = (raw_data & 0x200000000) != 0
+ is_branch = (raw_data & 0x100000000) != 0
+
+ if irq_active and not last_irq:
+ pc = 0x10
+
+ if pc >= 0:
+ if pc in insns:
+ insn_opcode, insn_desc = insns[pc]
+ opcode_fmt = "%08x" if (insn_opcode & 3) == 3 else " %04x"
+ print(("%s %s%08x | %08x | " + opcode_fmt + " | %s") % ("IRQ" if irq_active else " ",
+ ">" if is_branch else "@" if is_addr else "=", payload, pc, insn_opcode, insn_desc))
+ if not is_addr:
+ pc += 4 if (insn_opcode & 3) == 3 else 2
+ else:
+ print("%s %s%08x ** NO INFORMATION ON INSN AT %08x! **" % ("IRQ" if irq_active else " ",
+ ">" if is_branch else "@" if is_addr else "=", payload, pc))
+ pc = -1
+ else:
+ print("%s %s%08x ** SKIPPING DATA UNTIL NEXT BRANCH **" % ("IRQ" if irq_active else " ",
+ ">" if is_branch else "@" if is_addr else "=", payload))
+
+ if is_branch:
+ pc = payload
+
+ last_irq = irq_active
+