module: Allow .c32 files to execute themselves
[syslinux.git] / com32 / sysdump / main.c
blobeac931e5c65b26a4dd3915000667ec52c74dc907
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 "sysdump.h"
25 const char program[] = "sysdump";
26 const char version[] = "SYSDUMP " VERSION_STR " " DATE "\n";
28 __noreturn die(const char *msg)
30 printf("%s: %s\n", program, msg);
31 exit(1);
34 static void dump_all(struct upload_backend *be, const char *argv[])
36 cpio_init(be, argv);
38 cpio_writefile(be, "sysdump", version, sizeof version-1);
40 dump_memory_map(be);
41 dump_memory(be);
42 dump_dmi(be);
43 dump_acpi(be);
44 dump_cpuid(be);
45 dump_pci(be);
46 dump_vesa_tables(be);
48 cpio_close(be);
49 flush_data(be);
52 static struct upload_backend *upload_backends[] =
54 &upload_tftp,
55 &upload_ymodem,
56 &upload_srec,
57 NULL
60 __noreturn usage(void)
62 struct upload_backend **bep, *be;
64 printf("Usage:\n");
65 for (bep = upload_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 upload_backend **bep, *be;
75 fputs(version, stdout);
77 if (argc < 2)
78 usage();
80 for (bep = upload_backends ; (be = *bep) ; bep++) {
81 if (!strcmp(be->name, argv[1]))
82 break;
85 if (!be || argc < be->minargs + 2)
86 usage();
88 /* Do this as early as possible */
89 snapshot_lowmem();
91 printf("Backend: %s\n", be->name);
93 /* Do the actual data dump */
94 dump_all(be, (const char **)argv + 2);
96 return 0;