aboutsummaryrefslogtreecommitdiffstats
path: root/com32/sysdump/memory.c
blob: e7108d1e2d730c7d0454921c939b807d8d1979c2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
/*
 * 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)
{
    cpio_mkdir(be, "memory");

    if (lowmem)
	dump_memory_range(be, lowmem, zero_addr, lowmem_len);
}