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