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 exit(1); 50 } 51 52 int 53 main(int argc, char *argv[]) 54 { 55 char c, *progname; 56 char *dsdt_input_file, *dsdt_output_file; 57 struct ACPIsdt *rsdt, *sdt; 58 59 dsdt_input_file = dsdt_output_file = NULL; 60 progname = argv[0]; 61 62 if (argc < 2) 63 usage(progname); 64 65 while ((c = getopt(argc, argv, "dhtvf:o:")) != -1) { 66 switch (c) { 67 case 'd': 68 dflag = 1; 69 break; 70 case 't': 71 tflag = 1; 72 break; 73 case 'v': 74 vflag = 1; 75 break; 76 case 'f': 77 dsdt_input_file = optarg; 78 break; 79 case 'o': 80 dsdt_output_file = optarg; 81 break; 82 case 'h': 83 default: 84 usage(progname); 85 /* NOTREACHED */ 86 } 87 } 88 argc -= optind; 89 argv += optind; 90 91 /* Get input either from file or /dev/mem */ 92 if (dsdt_input_file != NULL) { 93 if (dflag == 0 && tflag == 0) { 94 warnx("Need to specify -d or -t with DSDT input file"); 95 usage(progname); 96 } else if (tflag != 0) { 97 warnx("Can't use -t with DSDT input file"); 98 usage(progname); 99 } 100 if (vflag) 101 warnx("loading DSDT file: %s", dsdt_input_file); 102 rsdt = dsdt_load_file(dsdt_input_file); 103 } else { 104 if (vflag) 105 warnx("loading RSD PTR from /dev/mem"); 106 rsdt = sdt_load_devmem(); 107 } 108 109 /* Display misc. SDT tables (only available when using /dev/mem) */ 110 if (tflag) { 111 if (vflag) 112 warnx("printing various SDT tables"); 113 sdt_print_all(rsdt); 114 } 115 116 /* Translate RSDT to DSDT pointer */ 117 if (dsdt_input_file == NULL) { 118 sdt = sdt_from_rsdt(rsdt, "FACP", NULL); 119 sdt = dsdt_from_fadt((struct FADTbody *)sdt->body); 120 } else { 121 sdt = rsdt; 122 rsdt = NULL; 123 } 124 125 /* Dump the DSDT and SSDTs to a file */ 126 if (dsdt_output_file != NULL) { 127 if (vflag) 128 warnx("saving DSDT file: %s", dsdt_output_file); 129 dsdt_save_file(dsdt_output_file, rsdt, sdt); 130 } 131 132 /* Disassemble the DSDT into ASL */ 133 if (dflag) { 134 if (vflag) 135 warnx("disassembling DSDT, iasl messages follow"); 136 aml_disassemble(rsdt, sdt); 137 if (vflag) 138 warnx("iasl processing complete"); 139 } 140 141 exit(0); 142 } 143