From: Luke Kenneth Casson Leighton Date: Sat, 29 May 2021 15:13:15 +0000 (+0100) Subject: dump memory from qemu in pypowersim X-Git-Tag: xlen-bcd~510 X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=9c44ab109c206c42b5cc8470e953044c1f85aed7;p=openpower-isa.git dump memory from qemu in pypowersim --- diff --git a/src/openpower/decoder/isa/pypowersim.py b/src/openpower/decoder/isa/pypowersim.py index 7f7c95e1..02f2685b 100644 --- a/src/openpower/decoder/isa/pypowersim.py +++ b/src/openpower/decoder/isa/pypowersim.py @@ -88,6 +88,7 @@ def read_entries(fname, listqty=None): return result + def qemu_register_compare(sim, q, regs, fprs): qpc, qxer, qcr, qlr = q.get_pc(), q.get_xer(), q.get_cr(), q.get_lr() sim_cr = sim.cr.value @@ -231,14 +232,10 @@ def run_tst(args, generator, qemu, if _pc is None: break - # cleanup - if qemu: - qemu.exit() - sim.add_process(process) sim.run() - return simulator + return simulator, qemu def help(): @@ -340,7 +337,7 @@ def run_simulation(): lst = f.read() with Program(lst, bigendian=False, orig_filename=binaryname) as prog: - simulator = run_tst(None, prog, qemu_cosim, + simulator, qemu = run_tst(None, prog, qemu_cosim, initial_regs, initial_sprs=initial_sprs, svstate=0, mmu=False, @@ -358,7 +355,14 @@ def run_simulation(): for fname, offs, length in write_to: write_data(simulator.mem, fname, offs, length) + if qemu: + qmem = qemu.get_mem(offs, length) + for i, mem in enumerate(qmem): + log(hex(offs+i*8), hex(mem)) + # cleanup + if qemu: + qemu.exit() if __name__ == "__main__": run_simulation() diff --git a/src/openpower/simulator/qemu.py b/src/openpower/simulator/qemu.py index d85e0bf5..de108649 100644 --- a/src/openpower/simulator/qemu.py +++ b/src/openpower/simulator/qemu.py @@ -69,6 +69,7 @@ class QemuController: def set_bytes(self, addr, v, wid): print("qemu set bytes", hex(addr), hex(v)) + v = swap_order(v, wid) faddr = '&{int}0x%x' % addr fmt = '"%%0%dx"' % (wid * 2) cmd = '-data-write-memory-bytes %s ' + fmt @@ -83,7 +84,7 @@ class QemuController: def get_mem(self, addr, nbytes): res = self.gdb.write("-data-read-memory %d u 1 1 %d" % - (addr, 8*nbytes)) + (addr, nbytes)) #print ("get_mem", res) for x in res: if(x["type"] == "result"): @@ -224,8 +225,6 @@ def run_program(program, initial_mem=None, extra_break_addr=None, q = QemuController(program.binfile.name, bigendian) q.connect() q.set_endian(init_endian) # easier to set variables this way - if initial_mem: - q.upload_mem(initial_mem, skip_zeros=True) # Run to the start of the program q.set_pc(start_addr) @@ -261,6 +260,10 @@ def run_program(program, initial_mem=None, extra_break_addr=None, # set endian before SPR set q.set_endian(bigendian) + # upload memory + if initial_mem: + q.upload_mem(initial_mem, skip_zeros=True) + # dump msr after endian set msr = q.get_msr() print("msr", bigendian, hex(msr), bin(msr)) diff --git a/src/test/basic_pypowersim/Makefile b/src/test/basic_pypowersim/Makefile index b2b5dd52..c4cbc4df 100644 --- a/src/test/basic_pypowersim/Makefile +++ b/src/test/basic_pypowersim/Makefile @@ -1,4 +1,4 @@ -TOOLCHAIN=powerpc64-linux-gnu +TOOLCHAIN=powerpc64le-linux-gnu CC=$(TOOLCHAIN)-gcc AS=$(TOOLCHAIN)-as AFLAGS=-mpwr9 @@ -8,7 +8,8 @@ all: sim sim: kernel.bin echo -n -e \\0060\\0000\\0061\\0000 > test.bin echo -n -e \\0060\\0000\\0061\\0000 >> test.bin - pypowersim --load test.bin:0 \ + pypowersim -q --load test.bin:0 \ + -p 0x20000000 \ --dump testout.bin:0x20000100:8 \ --dump testout2.bin:0x0:16 \ -g gpr.list -i kernel.bin