d0d40a7b48bfacfe4a7f3816bf5f483f2ad708d1
[external/syslinux.git] / com32 / sysdump / main.c
1 /* ----------------------------------------------------------------------- *
2  *
3  *   Copyright 2007-2008 H. Peter Anvin - All Rights Reserved
4  *   Copyright 2010 Intel Corporation; author: H. Peter Anvin
5  *
6  *   This program is free software; you can redistribute it and/or modify
7  *   it under the terms of the GNU General Public License as published by
8  *   the Free Software Foundation, Inc., 53 Temple Place Ste 330,
9  *   Boston MA 02111-1307, USA; either version 2 of the License, or
10  *   (at your option) any later version; incorporated herein by reference.
11  *
12  * ----------------------------------------------------------------------- */
13
14 #include <stdio.h>
15 #include <string.h>
16 #include <stdlib.h>
17 #include <stdbool.h>
18 #include <inttypes.h>
19 #include <dprintf.h>
20 #include <console.h>
21 #include <sys/cpu.h>
22 #include "../../version.h"
23 #include "backend.h"
24 #include "sysdump.h"
25
26 const char program[] = "sysdump";
27 const char version[] = "SYSDUMP " VERSION_STR " " DATE "\n";
28
29 __noreturn die(const char *msg)
30 {
31     printf("%s: %s\n", program, msg);
32     exit(1);
33 }
34
35 static void dump_all(struct backend *be, const char *argv[])
36 {
37     cpio_init(be, argv);
38
39     cpio_writefile(be, "sysdump", version, sizeof version-1);
40
41     dump_memory_map(be);
42     dump_memory(be);
43     dump_dmi(be);
44     dump_acpi(be);
45     dump_cpuid(be);
46     dump_pci(be);
47     dump_vesa_tables(be);
48
49     cpio_close(be);
50     flush_data(be);
51 }
52
53 static struct backend *backends[] =
54 {
55     &be_tftp,
56     &be_ymodem,
57     &be_srec,
58     NULL
59 };
60
61 __noreturn usage(void)
62 {
63     struct backend **bep, *be;
64
65     printf("Usage:\n");
66     for (bep = backends ; (be = *bep) ; bep++)
67         printf("    %s %s %s\n", program, be->name, be->helpmsg);
68
69     exit(1);
70 }
71
72 int main(int argc, char *argv[])
73 {
74     struct backend **bep, *be;
75
76     openconsole(&dev_null_r, &dev_stdcon_w);
77     fputs(version, stdout);
78
79     if (argc < 2)
80         usage();
81
82     for (bep = backends ; (be = *bep) ; bep++) {
83         if (!strcmp(be->name, argv[1]))
84             break;
85     }
86
87     if (!be || argc < be->minargs + 2)
88         usage();
89
90     /* Do this as early as possible */
91     snapshot_lowmem();
92
93     printf("Backend: %s\n", be->name);
94
95     /* Do the actual data dump */
96     dump_all(be, (const char **)argv + 2);
97
98     return 0;
99 }