Skip to contentSkip to conversation

physical memory dump to file

PATCH New kaizoku 1 participant 1 message Apr 10, 2008

lore
Share & tools
lore

kaizoku

author
#0 lore raw

PATCH 1/1 physical memory dump to file

This is just a quick little modification of memsave which saves the physical memory rather than the virtual memory.

--
Josh <[email protected]>

monitor.c +28 -0
diff -u qemu-old/monitor.c qemu/monitor.c
@@ -744,6 +744,32 @@
     fclose(f);
 }
 
+static void do_physical_memory_save(unsigned int valh, unsigned int vall,
+                           uint32_t size, const char *filename)
+{
+    FILE *f;
+    uint32_t l;
+    uint8_t buf[1024];
+    target_long addr = GET_TLONG(valh, vall);
+
+    f = fopen(filename, "wb");
+    if (!f) {
+        term_printf("could not open '%s'\n", filename);
+	return;
+    }
+    while (size != 0) {
+        l = sizeof(buf);
+        if (l > size)
+            l = size;
+        cpu_physical_memory_rw(addr, buf, l, 0);
+        fwrite(buf, 1, l, f);
+	fflush(f);
+        addr += l;
+        size -= l;
+    }
+    fclose(f);
+}
+
 static void do_sum(uint32_t start, uint32_t size)
 {
     uint32_t addr;
@@ -1328,6 +1354,8 @@
        "capture index", "stop capture" },
     { "memsave", "lis", do_memory_save,
       "addr size file", "save to disk virtual memory dump starting at 'addr' of size 'size'", },
+    { "pmemsave", "lis", do_physical_memory_save,
+      "addr size file", "save to disk physical memory dump starting at 'addr' of size 'size'", },
     { NULL, NULL, },
 };