6552e7f38bf561f37d0fd568a281abc6e58a5627
[external/syslinux.git] / com32 / sysdump / memory.c
1 /*
2  * Dump memory
3  */
4
5 #include <stdio.h>
6 #include <string.h>
7 #include <stdlib.h>
8 #include <sys/cpu.h>
9 #include "sysdump.h"
10 #include "backend.h"
11
12 static char *lowmem;
13 static size_t lowmem_len;
14
15 void *zero_addr;                /* Hack to keep gcc from complaining */
16
17 void snapshot_lowmem(void)
18 {
19     extern void _start(void);
20
21     lowmem_len = (size_t)_start;
22     lowmem = malloc(lowmem_len);
23     if (lowmem) {
24         printf("Snapshotting lowmem... ");
25         cli();
26         memcpy(lowmem, zero_addr, lowmem_len);
27         sti();
28         printf("ok\n");
29     }
30 }
31
32 static void dump_memory_range(struct backend *be, const void *where,
33                               const void *addr, size_t len)
34 {
35     char filename[32];
36
37     sprintf(filename, "memory/%08zx", (size_t)addr);
38     cpio_writefile(be, filename, where, len);
39 }
40
41 void dump_memory(struct backend *be)
42 {
43     printf("Dumping memory... ");
44
45     cpio_mkdir(be, "memory");
46
47     if (lowmem)
48         dump_memory_range(be, lowmem, zero_addr, lowmem_len);
49
50     printf("done.\n");
51 }