dump memory from qemu in pypowersim
authorLuke Kenneth Casson Leighton <lkcl@lkcl.net>
Sat, 29 May 2021 15:13:15 +0000 (16:13 +0100)
committerLuke Kenneth Casson Leighton <lkcl@lkcl.net>
Sat, 29 May 2021 15:13:21 +0000 (16:13 +0100)
src/openpower/decoder/isa/pypowersim.py
src/openpower/simulator/qemu.py
src/test/basic_pypowersim/Makefile

index 7f7c95e18f852d8af520e3f378a18e07c992a239..02f2685bf782f67876c625e7d22f2762525b2853 100644 (file)
@@ -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()
index d85e0bf5a28973697802985d3b4a232dcc6beec2..de108649c2b05a78de7d566796fc7efe466c90dd 100644 (file)
@@ -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))
index b2b5dd52925be84fc7991ba486b750526baa8967..c4cbc4df4baf03bffc23b246e8c80173436d51e6 100644 (file)
@@ -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