summaryrefslogtreecommitdiff
path: root/com32/sysdump/main.c
blob: f672585d1ee85c9797277b48bbeae6a9e1c72e39 (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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
/* ----------------------------------------------------------------------- *
 *
 *   Copyright 2007-2008 H. Peter Anvin - All Rights Reserved
 *   Copyright 2010 Intel Corporation; author: H. Peter Anvin
 *
 *   This program is free software; you can redistribute it and/or modify
 *   it under the terms of the GNU General Public License as published by
 *   the Free Software Foundation, Inc., 53 Temple Place Ste 330,
 *   Boston MA 02111-1307, USA; either version 2 of the License, or
 *   (at your option) any later version; incorporated herein by reference.
 *
 * ----------------------------------------------------------------------- */

#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <stdbool.h>
#include <inttypes.h>
#include <dprintf.h>
#include <console.h>
#include <sys/cpu.h>
#include <version.h>
#include "sysdump.h"

const char program[] = "sysdump";
const char version[] = "SYSDUMP " VERSION_STR " " DATE "\n";

__noreturn die(const char *msg)
{
    printf("%s: %s\n", program, msg);
    exit(1);
}

static void dump_all(struct upload_backend *be, const char *argv[])
{
    cpio_init(be, argv);

    cpio_writefile(be, "sysdump", version, sizeof version-1);

    dump_memory_map(be);
    dump_memory(be);
    dump_dmi(be);
    dump_acpi(be);
    dump_cpuid(be);
    dump_pci(be);
    dump_vesa_tables(be);

    cpio_close(be);
    flush_data(be);
}

static struct upload_backend *upload_backends[] =
{
    &upload_tftp,
    &upload_ymodem,
    &upload_srec,
    NULL
};

__noreturn usage(void)
{
    struct upload_backend **bep, *be;

    printf("Usage:\n");
    for (bep = upload_backends ; (be = *bep) ; bep++)
	printf("    %s %s %s\n", program, be->name, be->helpmsg);

    exit(1);
}

int main(int argc, char *argv[])
{
    struct upload_backend **bep, *be;

    openconsole(&dev_null_r, &dev_stdcon_w);
    fputs(version, stdout);

    if (argc < 2)
	usage();

    for (bep = upload_backends ; (be = *bep) ; bep++) {
	if (!strcmp(be->name, argv[1]))
	    break;
    }

    if (!be || argc < be->minargs + 2)
	usage();

    /* Do this as early as possible */
    snapshot_lowmem();

    printf("Backend: %s\n", be->name);

    /* Do the actual data dump */
    dump_all(be, (const char **)argv + 2);

    return 0;
}