1 /*- 2 * Copyright (c) 2000 Mitsuru IWASAKI <iwasaki@FreeBSD.org> 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright 9 * notice, this list of conditions and the following disclaimer. 10 * 2. Redistributions in binary form must reproduce the above copyright 11 * notice, this list of conditions and the following disclaimer in the 12 * documentation and/or other materials provided with the distribution. 13 * 14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 15 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 17 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24 * SUCH DAMAGE. 25 * 26 * $FreeBSD$ 27 */ 28 29 #include <sys/param.h> 30 #include <assert.h> 31 #include <err.h> 32 #include <stdio.h> 33 #include <stdlib.h> 34 #include <string.h> 35 #include <unistd.h> 36 37 #include "acpidump.h" 38 39 int dflag; /* Disassemble AML using iasl(8) */ 40 int tflag; /* Dump contents of SDT tables */ 41 int vflag; /* Use verbose messages */ 42 43 static void 44 usage(const char *progname) 45 { 46 47 fprintf(stderr, "usage: %s [-d] [-t] [-h] [-v] [-f dsdt_input] " 48 "[-o dsdt_output]\n", progname); 49 fprintf(stderr, "To send ASL:\n\t%s -dt | gzip -c9 > foo.asl.gz\n", 50 progname); 51 exit(1); 52 } 53 54 int 55 main(int argc, char *argv[]) 56 { 57 char c, *progname; 58 char *dsdt_input_file, *dsdt_output_file; 59 struct ACPIsdt *rsdt, *sdt; 60 61 dsdt_input_file = dsdt_output_file = NULL; 62 progname = argv[0]; 63 64 if (argc < 2) 65 usage(progname); 66 67 while ((c = getopt(argc, argv, "dhtvf:o:")) != -1) { 68 switch (c) { 69 case 'd': 70 dflag = 1; 71 break; 72 case 't': 73 tflag = 1; 74 break; 75 case 'v': 76 vflag = 1; 77 break; 78 case 'f': 79 dsdt_input_file = optarg; 80 break; 81 case 'o': 82 dsdt_output_file = optarg; 83 break; 84 case 'h': 85 default: 86 usage(progname); 87 /* NOTREACHED */ 88 } 89 } 90 argc -= optind; 91 argv += optind; 92 93 /* Get input either from file or /dev/mem */ 94 if (dsdt_input_file != NULL) { 95 if (dflag == 0 && tflag == 0) { 96 warnx("Need to specify -d or -t with DSDT input file"); 97 usage(progname); 98 } else if (tflag != 0) { 99 warnx("Can't use -t with DSDT input file"); 100 usage(progname); 101 } 102 if (vflag) 103 warnx("loading DSDT file: %s", dsdt_input_file); 104 rsdt = dsdt_load_file(dsdt_input_file); 105 } else { 106 if (vflag) 107 warnx("loading RSD PTR from /dev/mem"); 108 rsdt = sdt_load_devmem(); 109 } 110 111 /* Display misc. SDT tables (only available when using /dev/mem) */ 112 if (tflag) { 113 if (vflag) 114 warnx("printing various SDT tables"); 115 sdt_print_all(rsdt); 116 } 117 118 /* Translate RSDT to DSDT pointer */ 119 if (dsdt_input_file == NULL) { 120 sdt = sdt_from_rsdt(rsdt, "FACP", NULL); 121 sdt = dsdt_from_fadt((struct FADTbody *)sdt->body); 122 } else { 123 sdt = rsdt; 124 rsdt = NULL; 125 } 126 127 /* Dump the DSDT and SSDTs to a file */ 128 if (dsdt_output_file != NULL) { 129 if (vflag) 130 warnx("saving DSDT file: %s", dsdt_output_file); 131 dsdt_save_file(dsdt_output_file, rsdt, sdt); 132 } 133 134 /* Disassemble the DSDT into ASL */ 135 if (dflag) { 136 if (vflag) 137 warnx("disassembling DSDT, iasl messages follow"); 138 aml_disassemble(rsdt, sdt); 139 if (vflag) 140 warnx("iasl processing complete"); 141 } 142 143 exit(0); 144 } 145