From: Michael Nolan Date: Wed, 25 Mar 2020 22:38:18 +0000 (-0400) Subject: Directly compare simulator with qemu X-Git-Tag: div_pipeline~1631 X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=4b50a170c413f47e0527c843be49babc493c684b;p=soc.git Directly compare simulator with qemu I'm getting an error where it says some files are still open, but I can't figure out what they are --- diff --git a/src/soc/simulator/internalop_sim.py b/src/soc/simulator/internalop_sim.py index f7cd669c..3345c6b7 100644 --- a/src/soc/simulator/internalop_sim.py +++ b/src/soc/simulator/internalop_sim.py @@ -1,7 +1,8 @@ from soc.decoder.power_enums import (Function, Form, InternalOp, - In1Sel, In2Sel, In3Sel, OutSel, RC, LdstLen, - CryIn, get_csv, single_bit_flags, - get_signal_name, default_values) + In1Sel, In2Sel, In3Sel, OutSel, + RC, LdstLen, CryIn, get_csv, + single_bit_flags, + get_signal_name, default_values) import math @@ -66,12 +67,15 @@ class RegFile: print("Read {:x} from reg r{}".format(val, regnum)) return val + def assert_gpr(self, gpr, val): + reg_val = self.read_reg(gpr) + msg = "reg r{} got {:x}, expecting {:x}".format( + gpr, reg_val, val) + assert reg_val == val, msg + def assert_gprs(self, gprs): - for k,v in list(gprs.items()): - reg_val = self.read_reg(k) - msg = "reg r{} got {:x}, expecting {:x}".format( - k, reg_val, v) - assert reg_val == v, msg + for k, v in list(gprs.items()): + self.assert_gpr(k, v) class InternalOpSimulator: @@ -121,7 +125,7 @@ class InternalOpSimulator: internal_op = yield pdecode2.dec.op.internal_op addr_reg = yield pdecode2.e.read_reg1.data addr = self.regfile.read_reg(addr_reg) - + imm_ok = yield pdecode2.e.imm_data.ok r2_ok = yield pdecode2.e.read_reg2.ok width = yield pdecode2.e.data_len diff --git a/src/soc/simulator/program.py b/src/soc/simulator/program.py index d0b11d67..4466f99b 100644 --- a/src/soc/simulator/program.py +++ b/src/soc/simulator/program.py @@ -10,6 +10,7 @@ bigendian = True endian_fmt = "elf64-big" obj_fmt = "-be" + class Program: def __init__(self, instructions): if isinstance(instructions, list): @@ -17,9 +18,14 @@ class Program: self.assembly = instructions self._assemble() + def __enter__(self): + return self + + def __exit__(self, type, value, traceback): + self.close() + def _get_binary(self, elffile): self.binfile = tempfile.NamedTemporaryFile(suffix=".bin") - #self.binfile = open("kernel.bin", "wb+") args = ["powerpc64-linux-gnu-objcopy", "-O", "binary", "-I", endian_fmt, @@ -29,7 +35,6 @@ class Program: def _link(self, ofile): with tempfile.NamedTemporaryFile(suffix=".elf") as elffile: - #with open("kernel.elf", "wb+") as elffile: args = ["powerpc64-linux-gnu-ld", "-o", elffile.name, "-T", memmap, @@ -54,3 +59,16 @@ class Program: if not data: break yield struct.unpack('