Path: blob/main/usr.sbin/acpi/acpidump/acpidump.c
105216 views
/*-1* SPDX-License-Identifier: BSD-2-Clause2*3* Copyright (c) 2000 Mitsuru IWASAKI <[email protected]>4* All rights reserved.5*6* Redistribution and use in source and binary forms, with or without7* modification, are permitted provided that the following conditions8* are met:9* 1. Redistributions of source code must retain the above copyright10* notice, this list of conditions and the following disclaimer.11* 2. Redistributions in binary form must reproduce the above copyright12* notice, this list of conditions and the following disclaimer in the13* documentation and/or other materials provided with the distribution.14*15* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND16* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE17* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE18* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE19* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL20* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS21* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)22* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT23* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY24* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF25* SUCH DAMAGE.26*/2728#include <sys/param.h>29#include <assert.h>30#include <err.h>31#include <stdio.h>32#include <stdlib.h>33#include <string.h>34#include <unistd.h>3536#include "acpidump.h"3738int dflag; /* Disassemble AML using iasl(8) */39int tflag; /* Dump contents of SDT tables */40int vflag; /* Use verbose messages */4142static void43usage(const char *progname)44{4546fprintf(stderr, "usage: %s [-d] [-t] [-h] [-v] [-f dsdt_input] "47"[-o dsdt_output] [-T table_name]\n", progname);48fprintf(stderr, "To send ASL:\n\t%s -dt | gzip -c9 > foo.asl.gz\n",49progname);50exit(1);51}5253int54main(int argc, char *argv[])55{56ACPI_TABLE_HEADER *rsdt, *sdt;57int c;58char *progname;59char *dsdt_input_file, *dsdt_output_file;60char *tbl = NULL;6162dsdt_input_file = dsdt_output_file = NULL;63progname = argv[0];6465if (argc < 2)66usage(progname);6768while ((c = getopt(argc, argv, "df:ho:tT:vs")) != -1) {69switch (c) {70case 'd':71dflag = 1;72break;73case 'T':74tbl = optarg;75if (strlen(tbl) != 4) {76warnx("Illegal table name %s", tbl);77usage(progname);78}79break;80case 't':81tflag = 1;82break;83case 'v':84vflag = 1;85break;86case 'f':87dsdt_input_file = optarg;88break;89case 'o':90dsdt_output_file = optarg;91break;92case 's':93dflag = 2;94break;95case 'h':96default:97usage(progname);98/* NOTREACHED */99}100}101argc -= optind;102argv += optind;103104/* Get input either from file or /dev/mem */105if (dsdt_input_file != NULL) {106if (dflag == 0 && tflag == 0) {107warnx("Need to specify -d or -t with DSDT input file");108usage(progname);109} else if (tflag != 0) {110warnx("Can't use -t with DSDT input file");111usage(progname);112}113if (vflag)114warnx("loading DSDT file: %s", dsdt_input_file);115rsdt = dsdt_load_file(dsdt_input_file);116} else {117if (vflag)118warnx("loading RSD PTR from /dev/mem");119rsdt = sdt_load_devmem();120}121122/* Display misc. SDT tables (only available when using /dev/mem) */123if (tflag || tbl != NULL) {124if (vflag)125warnx("printing various SDT tables");126sdt_print_all(rsdt, tbl);127}128129/* Translate RSDT to DSDT pointer */130if (dsdt_input_file == NULL) {131sdt = sdt_from_rsdt(rsdt, ACPI_SIG_FADT, NULL);132sdt = dsdt_from_fadt((ACPI_TABLE_FADT *)sdt);133} else {134sdt = rsdt;135rsdt = NULL;136}137138/* Dump the DSDT and SSDTs to a file */139if (dsdt_output_file != NULL) {140if (vflag)141warnx("saving DSDT file: %s", dsdt_output_file);142dsdt_save_file(dsdt_output_file, rsdt, sdt);143}144145/* Disassemble the DSDT into ASL */146if (dflag) {147if (vflag)148warnx("disassembling DSDT, iasl messages follow");149if (dflag == 1) {150aml_disassemble(rsdt, sdt);151} else {152aml_disassemble_separate(rsdt, sdt);153}154if (vflag)155warnx("iasl processing complete");156}157158exit(0);159}160161162