Adding upstream version 4.00~pre53+dfsg.
[syslinux-debian/hramrach.git] / com32 / sysdump / main.c
blob26f562be3ee8d557e87dade547c0eb02362fd547
1 /* ----------------------------------------------------------------------- *
3 * Copyright 2007-2008 H. Peter Anvin - All Rights Reserved
4 * Copyright 2010 Intel Corporation; author: H. Peter Anvin
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.
12 * ----------------------------------------------------------------------- */
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"
26 const char program[] = "sysdump";
27 const char version[] = "SYSDUMP " VERSION_STR " " DATE "\n";
29 __noreturn die(const char *msg)
31 printf("%s: %s\n", program, msg);
32 exit(1);
35 static void dump_all(struct backend *be, const char *argv[])
37 cpio_init(be, argv);
39 cpio_writefile(be, "sysdump", version, sizeof version-1);
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);
49 cpio_close(be);
50 flush_data(be);
53 static struct backend *backends[] =
55 &be_tftp,
56 &be_ymodem,
57 NULL
60 __noreturn usage(void)
62 struct backend **bep, *be;
64 printf("Usage:\n");
65 for (bep = backends ; (be = *bep) ; bep++)
66 printf(" %s %s %s\n", program, be->name, be->helpmsg);
68 exit(1);
71 int main(int argc, char *argv[])
73 struct backend **bep, *be;
75 openconsole(&dev_null_r, &dev_stdcon_w);
76 fputs(version, stdout);
78 if (argc < 2)
79 usage();
81 for (bep = backends ; (be = *bep) ; bep++) {
82 if (!strcmp(be->name, argv[1]))
83 break;
86 if (!be || argc < be->minargs + 2)
87 usage();
89 /* Do this as early as possible */
90 snapshot_lowmem();
92 printf("Backend: %s\n", be->name);
94 /* Do the actual data dump */
95 dump_all(be, (const char **)argv + 2);
97 return 0;