summaryrefslogtreecommitdiffstats
path: root/contrib/syslinux-4.02/com32/sysdump/memory.c
diff options
context:
space:
mode:
Diffstat (limited to 'contrib/syslinux-4.02/com32/sysdump/memory.c')
-rw-r--r--contrib/syslinux-4.02/com32/sysdump/memory.c51
1 files changed, 51 insertions, 0 deletions
diff --git a/contrib/syslinux-4.02/com32/sysdump/memory.c b/contrib/syslinux-4.02/com32/sysdump/memory.c
new file mode 100644
index 0000000..6552e7f
--- /dev/null
+++ b/contrib/syslinux-4.02/com32/sysdump/memory.c
@@ -0,0 +1,51 @@
+/*
+ * Dump memory
+ */
+
+#include <stdio.h>
+#include <string.h>
+#include <stdlib.h>
+#include <sys/cpu.h>
+#include "sysdump.h"
+#include "backend.h"
+
+static char *lowmem;
+static size_t lowmem_len;
+
+void *zero_addr; /* Hack to keep gcc from complaining */
+
+void snapshot_lowmem(void)
+{
+ extern void _start(void);
+
+ lowmem_len = (size_t)_start;
+ lowmem = malloc(lowmem_len);
+ if (lowmem) {
+ printf("Snapshotting lowmem... ");
+ cli();
+ memcpy(lowmem, zero_addr, lowmem_len);
+ sti();
+ printf("ok\n");
+ }
+}
+
+static void dump_memory_range(struct backend *be, const void *where,
+ const void *addr, size_t len)
+{
+ char filename[32];
+
+ sprintf(filename, "memory/%08zx", (size_t)addr);
+ cpio_writefile(be, filename, where, len);
+}
+
+void dump_memory(struct backend *be)
+{
+ printf("Dumping memory... ");
+
+ cpio_mkdir(be, "memory");
+
+ if (lowmem)
+ dump_memory_range(be, lowmem, zero_addr, lowmem_len);
+
+ printf("done.\n");
+}