summaryrefslogtreecommitdiff
path: root/com32/sysdump/memory.c
blob: 377f9a99a7ea45c26988d5efe267d803e39012b3 (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
48
49
50
/*
 * Dump memory
 */

#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <sys/cpu.h>
#include "sysdump.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 upload_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 upload_backend *be)
{
    printf("Dumping memory... ");

    cpio_mkdir(be, "memory");

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

    printf("done.\n");
}