-
Notifications
You must be signed in to change notification settings - Fork 543
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update google_riscv-dv to chipsalliance/riscv-dv@08b1206
Update code from upstream repository https://github.com/chipsalliance/riscv-dv to revision 08b12066b34c9728f706e45098ba502a36d7ca59 Signed-off-by: Marno van der Maas <mvdmaas+git@lowrisc.org>
- Loading branch information
1 parent
44ed214
commit f60d03b
Showing
11 changed files
with
294 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file removed
BIN
-12 KB
vendor/google_riscv-dv/pygen/pygen_src/test/.riscv_instr_base_test.py.swp
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
156 changes: 156 additions & 0 deletions
156
vendor/google_riscv-dv/scripts/renode_log_to_trace_csv.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,156 @@ | ||
#!/usr/bin/env python3 | ||
""" | ||
Converts Renode log to execution trace for RISC-V DV | ||
""" | ||
|
||
import argparse | ||
import os | ||
import re | ||
import sys | ||
import logging | ||
|
||
sys.path.insert(0, os.path.dirname(os.path.realpath(__file__))) | ||
|
||
from riscv_trace_csv import * | ||
from lib import * | ||
|
||
# ============================================================================= | ||
|
||
GPR_NAMES = [ | ||
("x0", "zero"), | ||
("x1", "ra"), | ||
("x2", "sp"), | ||
("x3", "gp"), | ||
("x4", "tp"), | ||
("x5", "t0"), | ||
("x6", "t1"), | ||
("x7", "t2"), | ||
("x8", "s0"), | ||
("x9", "s1"), | ||
("x10", "a0"), | ||
("x11", "a1"), | ||
("x12", "a2"), | ||
("x13", "a3"), | ||
("x14", "a4"), | ||
("x15", "a5"), | ||
("x16", "a6"), | ||
("x17", "a7"), | ||
("x18", "s2"), | ||
("x19", "s3"), | ||
("x20", "s4"), | ||
("x21", "s5"), | ||
("x22", "s6"), | ||
("x23", "s7"), | ||
("x24", "s8"), | ||
("x25", "s9"), | ||
("x26", "s10"), | ||
("x27", "s11"), | ||
("x28", "t3"), | ||
("x29", "t4"), | ||
("x30", "t5"), | ||
("x31", "t6"), | ||
] | ||
|
||
# ============================================================================= | ||
|
||
|
||
def process_renode_sim_log(log_name, csv_name): | ||
""" | ||
Converts a Renode trace log to CSV format | ||
""" | ||
|
||
# Build lookups | ||
gpr_to_name = {m[0]: m[1] for m in GPR_NAMES} | ||
known_gpr = {m[0].upper() for m in GPR_NAMES} | ||
|
||
# FIXME: We need a previous PC each time. Assume its value for the first | ||
# entry. | ||
prev_pc = "80000000" | ||
|
||
# FIXME: Assume initial state of all GPR set to 0 | ||
state = {m[0].upper(): "0" for m in GPR_NAMES} | ||
trace = [] | ||
|
||
with open(log_name, "r") as fp: | ||
for line in fp: | ||
|
||
line = line.strip() | ||
if not line: | ||
continue | ||
|
||
# Skip non-regdump | ||
if not line.startswith("REGDUMP:"): | ||
continue | ||
|
||
# Decode state | ||
fields = line.replace("REGDUMP:", "").split(",") | ||
regs = {fields[i]: fields[i+1] for i in range(0, len(fields), 2)} | ||
|
||
# Compute state difference | ||
diff = {r: regs[r] for r in known_gpr \ | ||
if r in state and r in regs and state[r] != regs[r]} | ||
state = regs | ||
|
||
# Format the entry | ||
entry = RiscvInstructionTraceEntry() | ||
entry.pc = prev_pc | ||
entry.binary = "0" | ||
entry.operand = "" | ||
entry.mode = "0" | ||
|
||
# GPRs | ||
for x in range(32): | ||
name = "X{}".format(x) | ||
if name in diff: | ||
lname = name.lower() | ||
value = int(diff[name], 16) | ||
entry.gpr.append("{}:{:08x}".format(gpr_to_name[lname], value)) | ||
|
||
# CSRs | ||
# TODO: | ||
|
||
# Add only if there is a GPR/CSR change | ||
if entry.gpr or entry.csr: | ||
trace.append(entry) | ||
|
||
prev_pc = state["PC"] | ||
|
||
return trace | ||
|
||
|
||
def write_csv(file_name, data): | ||
""" | ||
Writes the trace to CSV | ||
""" | ||
|
||
with open(file_name, "w") as fp: | ||
|
||
writer = RiscvInstructionTraceCsv(fp) | ||
writer.start_new_trace() | ||
|
||
for entry in data: | ||
writer.write_trace_entry(entry) | ||
|
||
# ============================================================================ | ||
|
||
|
||
def main(): | ||
# Parse input arguments | ||
parser = argparse.ArgumentParser() | ||
parser.add_argument("--log", type=str, help="Input Renode simulation log") | ||
parser.add_argument("--csv", type=str, help="Output trace CSV file") | ||
parser.add_argument("-v", "--verbose", dest="verbose", action="store_true", | ||
help="Verbose logging") | ||
parser.set_defaults(verbose=False) | ||
|
||
args = parser.parse_args() | ||
setup_logging(args.verbose) | ||
|
||
# Process Renode log | ||
trace = process_renode_sim_log(args.log, args.csv) | ||
# Write CSV | ||
write_csv(args.csv, trace) | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
#!/usr/bin/env python3 | ||
import argparse | ||
import subprocess | ||
import os | ||
import tempfile | ||
|
||
# ============================================================================= | ||
|
||
REPL_TEMPLATE = """ | ||
memory: Memory.MappedMemory @ sysbus 0x80000000 | ||
size: 0x10000 | ||
cpu: CPU.RiscV32 @ sysbus | ||
cpuType: "{isa}" | ||
timeProvider: clint | ||
hartId: 0 | ||
clint: IRQControllers.CoreLevelInterruptor @ sysbus 0x02000000 | ||
[0,1] -> cpu@[3,7] | ||
frequency: 1000000 | ||
""" | ||
|
||
RESC_TEMPLATE = """ | ||
using sysbus | ||
mach create "riscv" | ||
machine LoadPlatformDescription @{repl} | ||
sysbus LoadELF @{elf} | ||
cpu MaximumBlockSize 1 | ||
cpu SetHookAtBlockEnd "print('REGDUMP:' + ','.join(self.GetRegistersValues()))" | ||
emulation RunFor "0.000100" | ||
quit | ||
""" | ||
|
||
# ============================================================================= | ||
|
||
|
||
def main(): | ||
""" | ||
The entry point | ||
""" | ||
|
||
parser = argparse.ArgumentParser() | ||
|
||
parser.add_argument( | ||
"--renode", | ||
type=str, | ||
default="renode", | ||
help="Path to Renode binary", | ||
) | ||
parser.add_argument( | ||
"--log", | ||
type=str, | ||
default=None, | ||
help="Output log file", | ||
) | ||
parser.add_argument( | ||
"--isa", | ||
type=str, | ||
default="rv32i", | ||
help="RISC-V ISA specification string", | ||
) | ||
parser.add_argument( | ||
"--elf", | ||
type=str, | ||
required=True, | ||
help="ELF file to run", | ||
) | ||
|
||
args = parser.parse_args() | ||
|
||
with tempfile.TemporaryDirectory() as tmpdir: | ||
|
||
repl = os.path.join(tmpdir, "riscv.repl") | ||
resc = os.path.join(tmpdir, "riscv.resc") | ||
|
||
params = { | ||
"renode": args.renode, | ||
"isa": args.isa, | ||
"elf": args.elf, | ||
"repl": repl, | ||
"resc": resc, | ||
"log": args.log, | ||
} | ||
|
||
# Render REPL template | ||
with open(repl, "w") as fp: | ||
fp.write(REPL_TEMPLATE.format(**params)) | ||
|
||
# Render RESC template | ||
with open(resc, "w") as fp: | ||
fp.write(RESC_TEMPLATE.format(**params)) | ||
|
||
# Launch Renode, capture output | ||
cmd = "{renode} --console -p {resc}".format(**params) | ||
if args.log is not None: | ||
cmd += " &>{log}".format(**params) | ||
|
||
subprocess.call(cmd, shell=True) | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters