diff options
author | iwasaki <iwasaki@FreeBSD.org> | 2000-08-31 14:42:32 +0000 |
---|---|---|
committer | iwasaki <iwasaki@FreeBSD.org> | 2000-08-31 14:42:32 +0000 |
commit | 2e85c753ff2a06d63fc5a84465b82b20050ce764 (patch) | |
tree | 23899ceab8a4e161501652d7fc17c170741bca01 /usr.sbin/acpi/acpidump | |
parent | 8b89c74a2fdb081292974b38082f6bc9fa534b59 (diff) | |
download | FreeBSD-src-2e85c753ff2a06d63fc5a84465b82b20050ce764.zip FreeBSD-src-2e85c753ff2a06d63fc5a84465b82b20050ce764.tar.gz |
import acpidump(8) from ACPI For FreeBSD project.
Obtained from: ACPI For FreeBSD project
Diffstat (limited to 'usr.sbin/acpi/acpidump')
-rw-r--r-- | usr.sbin/acpi/acpidump/Makefile | 10 | ||||
-rw-r--r-- | usr.sbin/acpi/acpidump/acpi.c | 258 | ||||
-rw-r--r-- | usr.sbin/acpi/acpidump/acpi_user.c | 165 | ||||
-rw-r--r-- | usr.sbin/acpi/acpidump/acpidump.c | 103 | ||||
-rw-r--r-- | usr.sbin/acpi/acpidump/acpidump.h | 44 | ||||
-rw-r--r-- | usr.sbin/acpi/acpidump/aml_dump.c | 59 | ||||
-rw-r--r-- | usr.sbin/acpi/acpidump/asl_dump.c | 1209 |
7 files changed, 1848 insertions, 0 deletions
diff --git a/usr.sbin/acpi/acpidump/Makefile b/usr.sbin/acpi/acpidump/Makefile new file mode 100644 index 0000000..346dcf2 --- /dev/null +++ b/usr.sbin/acpi/acpidump/Makefile @@ -0,0 +1,10 @@ +# $Id: Makefile,v 1.2 2000/07/14 18:16:29 iwasaki Exp $ +# $FreeBSD$ + +PROG= acpidump +SRCS= acpi.c acpi_user.c asl_dump.c aml_dump.c acpidump.c +NOMAN= yes +#MAN8= acpidump.8 +#DEBUG_FLAGS= -g + +.include <bsd.prog.mk> diff --git a/usr.sbin/acpi/acpidump/acpi.c b/usr.sbin/acpi/acpidump/acpi.c new file mode 100644 index 0000000..d52a0d9 --- /dev/null +++ b/usr.sbin/acpi/acpidump/acpi.c @@ -0,0 +1,258 @@ +/*- + * Copyright (c) 1998 Doug Rabson + * Copyright (c) 2000 Mitsuru IWASAKI <iwasaki@FreeBSD.org> + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $Id: acpi.c,v 1.4 2000/08/09 14:47:52 iwasaki Exp $ + * $FreeBSD$ + */ + +#include <sys/param.h> +#include <sys/stat.h> +#include <sys/acpi.h> + +#include <assert.h> +#include <err.h> +#include <fcntl.h> +#include <stdio.h> +#include <unistd.h> + +#include "acpidump.h" + +static void +acpi_print_string(char *s, size_t length) +{ + int c; + + /* Trim trailing spaces and NULLs */ + while (length > 0 && (s[length - 1] == ' ' || s[length - 1] == '\0')) + length--; + + while (length--) { + c = *s++; + putchar(c); + } +} + +static void +acpi_handle_dsdt(struct ACPIsdt *dsdp) +{ + u_int8_t *dp; + u_int8_t *end; + + acpi_print_dsdt(dsdp); + dp = (u_int8_t *)dsdp->body; + end = (u_int8_t *)dsdp + dsdp->len; + asl_dump_objectlist(&dp, end, 0); + assert(dp == end); +} + +static void +acpi_handle_facp(struct FACPbody *facp) +{ + struct ACPIsdt *dsdp; + + acpi_print_facp(facp); + dsdp = (struct ACPIsdt *) acpi_map_sdt(facp->dsdt_ptr); + if (acpi_checksum(dsdp, dsdp->len)) + errx(1, "DSDT is corrupt\n"); + acpi_handle_dsdt(dsdp); + aml_dump(dsdp->body, dsdp->len - SIZEOF_SDT_HDR); +} + +/* + * Public interfaces + */ + +void +acpi_print_sdt(struct ACPIsdt *sdp) +{ + + acpi_print_string(sdp->signature, 4); + printf(": Lenth=%d, Revision=%d, Checksum=%d,\n", + sdp->len, sdp->rev, sdp->check); + printf("\tOEMID="); + acpi_print_string(sdp->oemid, 6); + printf(", OEM Table ID="); + acpi_print_string(sdp->oemtblid, 8); + printf(", OEM Revision=0x%x,\n", sdp->oemrev); + printf("\tCreator ID="); + acpi_print_string(sdp->creator, 4); + printf(", Creator Revision=0x%x\n", sdp->crerev); +} + +void +acpi_print_rsdt(struct ACPIsdt *rsdp) +{ + int i, entries; + + acpi_print_sdt(rsdp); + entries = (rsdp->len - SIZEOF_SDT_HDR) / sizeof(u_int32_t); + printf("\tEntries={ "); + for (i = 0; i < entries; i++) { + if (i > 0) + printf(", "); + printf("0x%08x", rsdp->body[i]); + } + printf(" }\n"); +} + +void +acpi_print_facp(struct FACPbody *facp) +{ + char sep; + + printf("\tDSDT=0x%x\n", facp->dsdt_ptr); + printf("\tINT_MODEL=%s\n", facp->int_model ? "APIC" : "PIC"); + printf("\tSCI_INT=%d\n", facp->sci_int); + printf("\tSMI_CMD=0x%x, ", facp->smi_cmd); + printf("ACPI_ENABLE=0x%x, ", facp->acpi_enable); + printf("ACPI_DISABLE=0x%x, ", facp->acpi_disable); + printf("S4BIOS_REQ=0x%x\n", facp->s4biosreq); + if (facp->pm1a_evt_blk) + printf("\tPM1a_EVT_BLK=0x%x-0x%x\n", + facp->pm1a_evt_blk, + facp->pm1a_evt_blk + facp->pm1_evt_len - 1); + if (facp->pm1b_evt_blk) + printf("\tPM1b_EVT_BLK=0x%x-0x%x\n", + facp->pm1b_evt_blk, + facp->pm1b_evt_blk + facp->pm1_evt_len - 1); + if (facp->pm1a_cnt_blk) + printf("\tPM1a_CNT_BLK=0x%x-0x%x\n", + facp->pm1a_cnt_blk, + facp->pm1a_cnt_blk + facp->pm1_cnt_len - 1); + if (facp->pm1b_cnt_blk) + printf("\tPM1b_CNT_BLK=0x%x-0x%x\n", + facp->pm1b_cnt_blk, + facp->pm1b_cnt_blk + facp->pm1_cnt_len - 1); + if (facp->pm2_cnt_blk) + printf("\tPM2_CNT_BLK=0x%x-0x%x\n", + facp->pm2_cnt_blk, + facp->pm2_cnt_blk + facp->pm2_cnt_len - 1); + if (facp->pm_tmr_blk) + printf("\tPM2_TMR_BLK=0x%x-0x%x\n", + facp->pm_tmr_blk, + facp->pm_tmr_blk + facp->pm_tmr_len - 1); + if (facp->gpe0_blk) + printf("\tPM2_GPE0_BLK=0x%x-0x%x\n", + facp->gpe0_blk, + facp->gpe0_blk + facp->gpe0_len - 1); + if (facp->gpe1_blk) + printf("\tPM2_GPE1_BLK=0x%x-0x%x, GPE1_BASE=%d\n", + facp->gpe1_blk, + facp->gpe1_blk + facp->gpe1_len - 1, + facp->gpe1_base); + printf("\tP_LVL2_LAT=%dms, P_LVL3_LAT=%dms\n", + facp->p_lvl2_lat, facp->p_lvl3_lat); + printf("\tFLUSH_SIZE=%d, FLUSH_STRIDE=%d\n", + facp->flush_size, facp->flush_stride); + printf("\tDUTY_OFFSET=%d, DUTY_WIDTH=%d\n", + facp->duty_off, facp->duty_width); + printf("\tDAY_ALRM=%d, MON_ALRM=%d, CENTURY=%d\n", + facp->day_alrm, facp->mon_alrm, facp->century); + printf("\tFlags="); + sep = '{'; + +#define PRINTFLAG(xx) do { \ + if (facp->flags & ACPI_FACP_FLAG_## xx) { \ + printf("%c%s", sep, #xx); sep = ','; \ + } \ +} while (0) + + PRINTFLAG(WBINVD); + PRINTFLAG(WBINVD_FLUSH); + PRINTFLAG(PROC_C1); + PRINTFLAG(P_LVL2_UP); + PRINTFLAG(PWR_BUTTON); + PRINTFLAG(SLP_BUTTON); + PRINTFLAG(FIX_RTC); + PRINTFLAG(RTC_S4); + PRINTFLAG(TMR_VAL_EXT); + PRINTFLAG(DCK_CAP); + +#undef PRINTFLAG + + printf("}\n"); +} + +void +acpi_print_dsdt(struct ACPIsdt *dsdp) +{ + + acpi_print_sdt(dsdp); +} + +int +acpi_checksum(void *p, size_t length) +{ + u_int8_t *bp; + u_int8_t sum; + + bp = p; + sum = 0; + while (length--) + sum += *bp++; + + return (sum); +} + +struct ACPIsdt * +acpi_map_sdt(vm_offset_t pa) +{ + struct ACPIsdt *sp; + + sp = acpi_map_physical(pa, sizeof(struct ACPIsdt)); + sp = acpi_map_physical(pa, sp->len); + return (sp); +} + +void +acpi_print_rsd_ptr(struct ACPIrsdp *rp) +{ + + printf("RSD PTR: Checksum=%d, OEMID=", rp->sum); + acpi_print_string(rp->oem, 6); + printf(", RsdtAddress=0x%08x\n", rp->addr); +} + +void +acpi_handle_rsdt(struct ACPIsdt *rsdp) +{ + int i; + int entries; + struct ACPIsdt *sdp; + + entries = (rsdp->len - SIZEOF_SDT_HDR) / sizeof(u_int32_t); + acpi_print_rsdt(rsdp); + for (i = 0; i < entries; i++) { + sdp = (struct ACPIsdt *) acpi_map_sdt(rsdp->body[i]); + if (acpi_checksum(sdp, sdp->len)) + errx(1, "RSDT entry %d is corrupt\n", i); + if (!memcmp(sdp->signature, "FACP", 4)) { + acpi_handle_facp((struct FACPbody *) sdp->body); + } else { + acpi_print_sdt(sdp); + } + } +} diff --git a/usr.sbin/acpi/acpidump/acpi_user.c b/usr.sbin/acpi/acpidump/acpi_user.c new file mode 100644 index 0000000..56d21e7 --- /dev/null +++ b/usr.sbin/acpi/acpidump/acpi_user.c @@ -0,0 +1,165 @@ +/*- + * Copyright (c) 1999 Doug Rabson + * Copyright (c) 2000 Mitsuru IWASAKI <iwasaki@FreeBSD.org> + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $Id: acpi_user.c,v 1.5 2000/08/09 14:47:52 iwasaki Exp $ + * $FreeBSD$ + */ + +#include <sys/param.h> +#include <sys/mman.h> +#include <sys/queue.h> +#include <sys/stat.h> +#include <sys/acpi.h> + +#include <err.h> +#include <fcntl.h> +#include <stdlib.h> +#include <string.h> +#include <unistd.h> + +#include "acpidump.h" + +static int acpi_mem_fd = -1; + +struct acpi_user_mapping { + LIST_ENTRY(acpi_user_mapping) link; + vm_offset_t pa; + caddr_t va; + size_t size; +}; + +LIST_HEAD(acpi_user_mapping_list, acpi_user_mapping) maplist; + +static void +acpi_user_init() +{ + + if (acpi_mem_fd == -1) { + acpi_mem_fd = open("/dev/mem", O_RDONLY); + if (acpi_mem_fd == -1) + err(1, "opening /dev/mem"); + LIST_INIT(&maplist); + } +} + +static struct acpi_user_mapping * +acpi_user_find_mapping(vm_offset_t pa, size_t size) +{ + struct acpi_user_mapping *map; + + /* First search for an existing mapping */ + for (map = LIST_FIRST(&maplist); map; map = LIST_NEXT(map, link)) { + if (map->pa <= pa && map->size >= pa + size - map->pa) + return (map); + } + + /* Then create a new one */ + size = round_page(pa + size) - trunc_page(pa); + pa = trunc_page(pa); + map = malloc(sizeof(struct acpi_user_mapping)); + if (!map) + errx(1, "out of memory"); + map->pa = pa; + map->va = mmap(0, size, PROT_READ, MAP_SHARED, acpi_mem_fd, pa); + map->size = size; + if ((intptr_t) map->va == -1) + err(1, "can't map address"); + LIST_INSERT_HEAD(&maplist, map, link); + + return (map); +} + +/* + * Public interfaces + */ + +struct ACPIrsdp * +acpi_find_rsd_ptr() +{ + int i; + u_int8_t buf[sizeof(struct ACPIrsdp)]; + + acpi_user_init(); + for (i = 0; i < 1024 * 1024; i += 16) { + read(acpi_mem_fd, buf, 16); + if (!memcmp(buf, "RSD PTR ", 8)) { + /* Read the rest of the structure */ + read(acpi_mem_fd, buf + 16, sizeof(struct ACPIrsdp) - 16); + + /* Verify checksum before accepting it. */ + if (acpi_checksum(buf, sizeof(struct ACPIrsdp))) + continue; + return (acpi_map_physical(i, sizeof(struct ACPIrsdp))); + } + } + + return (0); +} + +void * +acpi_map_physical(vm_offset_t pa, size_t size) +{ + struct acpi_user_mapping *map; + + map = acpi_user_find_mapping(pa, size); + return (map->va + (pa - map->pa)); +} + +void +acpi_load_dsdt(char *dumpfile, u_int8_t **dpp, u_int8_t **endp) +{ + u_int8_t *dp; + u_int8_t *end; + struct stat sb; + + if ((acpi_mem_fd = open(dumpfile, O_RDONLY)) == -1) { + errx(1, "opening %s\n", dumpfile); + } + + LIST_INIT(&maplist); + + if (fstat(acpi_mem_fd, &sb) == -1) { + errx(1, "fstat %s\n", dumpfile); + } + + dp = mmap(0, sb.st_size, PROT_READ, MAP_PRIVATE, acpi_mem_fd, 0); + if (dp == NULL) { + errx(1, "mmap %s\n", dumpfile); + } + + /* + * Microsoft asl.exe generates 0x23 byte additional info. + * at the begining of the file, so just ignore it. + */ + if (strncmp(dp, "DSDT", 4) == 0) { + dp += 0x23; + sb.st_size -= 0x23; + } + + end = (u_int8_t *) dp + sb.st_size; + *dpp = dp; + *endp = end; +} diff --git a/usr.sbin/acpi/acpidump/acpidump.c b/usr.sbin/acpi/acpidump/acpidump.c new file mode 100644 index 0000000..a61f9d6 --- /dev/null +++ b/usr.sbin/acpi/acpidump/acpidump.c @@ -0,0 +1,103 @@ +/*- + * Copyright (c) 2000 Mitsuru IWASAKI <iwasaki@FreeBSD.org> + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $Id: acpidump.c,v 1.3 2000/08/08 14:12:21 iwasaki Exp $ + * $FreeBSD$ + */ + +#include <sys/param.h> +#include <sys/acpi.h> + +#include <assert.h> +#include <err.h> +#include <stdio.h> +#include <unistd.h> + +#include "acpidump.h" + +static void +asl_dump_from_file(char *file) +{ + u_int8_t *dp; + u_int8_t *end; + + acpi_load_dsdt(file, &dp, &end); + asl_dump_objectlist(&dp, end, 0); +} + +static void +asl_dump_from_devmem() +{ + struct ACPIrsdp *rp; + struct ACPIsdt *rsdp; + + rp = acpi_find_rsd_ptr(); + if (!rp) + errx(1, "Can't find ACPI information\n"); + + acpi_print_rsd_ptr(rp); + rsdp = (struct ACPIsdt *) acpi_map_sdt(rp->addr); + if (memcmp(rsdp->signature, "RSDT", 4) || + acpi_checksum(rsdp, rsdp->len)) + errx(1, "RSDT is corrupted\n"); + + acpi_handle_rsdt(rsdp); +} + +static void +usage(const char *progname) +{ + + printf("usage:\t%s [-o dsdt_file_for_output]\n", progname); + printf("or\t%s [-f dsdt_file_for_input]\n", progname); + exit(1); +} + +int +main(int argc, char *argv[]) +{ + char c, *progname; + + progname = argv[0]; + while ((c = getopt(argc, argv, "f:o:h")) != -1) { + switch (c) { + case 'f': + asl_dump_from_file(optarg); + return (0); + case 'o': + aml_dumpfile = optarg; + break; + case 'h': + usage(progname); + break; + default: + argc -= optind; + argv += optind; + } + } + + asl_dump_from_devmem(); + return (0); +} diff --git a/usr.sbin/acpi/acpidump/acpidump.h b/usr.sbin/acpi/acpidump/acpidump.h new file mode 100644 index 0000000..fab7e1a --- /dev/null +++ b/usr.sbin/acpi/acpidump/acpidump.h @@ -0,0 +1,44 @@ +/*- + * Copyright (c) 1999 Doug Rabson + * Copyright (c) 2000 Mitsuru IWASAKI <iwasaki@FreeBSD.org> + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $Id: acpidump.h,v 1.3 2000/08/09 14:47:52 iwasaki Exp $ + * $FreeBSD$ + */ + +#ifndef _ACPIDUMP_H_ +#define _ACPIDUMP_H_ + +void asl_dump_termobj(u_int8_t **, int); +void asl_dump_objectlist(u_int8_t **, u_int8_t *, int); + +void aml_dump(u_int32_t *, int); + +void acpi_handle_rsdt(struct ACPIsdt *); +void acpi_load_dsdt(char *, u_int8_t **, u_int8_t **); + +extern char *aml_dumpfile; + +#endif /* !_ACPIDUMP_H_ */ diff --git a/usr.sbin/acpi/acpidump/aml_dump.c b/usr.sbin/acpi/acpidump/aml_dump.c new file mode 100644 index 0000000..6176df3 --- /dev/null +++ b/usr.sbin/acpi/acpidump/aml_dump.c @@ -0,0 +1,59 @@ +/*- + * Copyright (c) 2000 Mitsuru IWASAKI <iwasaki@FreeBSD.org> + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $Id: aml_dump.c,v 1.3 2000/08/08 14:12:21 iwasaki Exp $ + * $FreeBSD$ + */ + +#include <sys/param.h> +#include <sys/stat.h> +#include <sys/acpi.h> + +#include <fcntl.h> +#include <stdio.h> +#include <unistd.h> + +#include "acpidump.h" + +char *aml_dumpfile = NULL; + +void +aml_dump(u_int32_t *ptr, int len) +{ + int fd; + mode_t mode; + + if (aml_dumpfile == NULL) { + return; + } + + mode = (S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH); + fd = open(aml_dumpfile, O_WRONLY | O_CREAT, mode); + if (fd == -1) { + return; + } + write(fd, ptr, len); + close(fd); +} diff --git a/usr.sbin/acpi/acpidump/asl_dump.c b/usr.sbin/acpi/acpidump/asl_dump.c new file mode 100644 index 0000000..4cbd362 --- /dev/null +++ b/usr.sbin/acpi/acpidump/asl_dump.c @@ -0,0 +1,1209 @@ +/*- + * Copyright (c) 1999 Doug Rabson + * Copyright (c) 2000 Mitsuru IWASAKI <iwasaki@FreeBSD.org> + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $Id: asl_dump.c,v 1.6 2000/08/09 14:47:52 iwasaki Exp $ + * $FreeBSD$ + */ + +#include <sys/param.h> +#include <sys/acpi.h> + +#include <assert.h> +#include <err.h> +#include <stdio.h> + +#include "acpidump.h" + +static u_int32_t +asl_dump_pkglength(u_int8_t **dpp) +{ + u_int8_t *dp; + u_int32_t pkglength; + + dp = *dpp; + pkglength = *dp++; + switch (pkglength >> 6) { + case 0: + break; + case 1: + pkglength = (pkglength & 0xf) + (dp[0] << 4); + dp += 1; + break; + case 2: + pkglength = (pkglength & 0xf) + (dp[0] << 4) + (dp[1] << 12); + dp += 2; + break; + case 3: + pkglength = (pkglength & 0xf) + + (dp[0] << 4) + (dp[1] << 12) + (dp[2] << 20); + dp += 3; + break; + } + + *dpp = dp; + return (pkglength); +} + +static void +print_nameseg(u_int8_t *dp) +{ + + if (dp[3] != '_') + printf("%c%c%c%c", dp[0], dp[1], dp[2], dp[3]); + else if (dp[2] != '_') + printf("%c%c%c_", dp[0], dp[1], dp[2]); + else if (dp[1] != '_') + printf("%c%c__", dp[0], dp[1]); + else if (dp[0] != '_') + printf("%c___", dp[0]); +} + +static u_int8_t +asl_dump_bytedata(u_int8_t **dpp) +{ + u_int8_t *dp; + u_int8_t data; + + dp = *dpp; + data = dp[0]; + *dpp = dp + 1; + return (data); +} + +static u_int16_t +asl_dump_worddata(u_int8_t **dpp) +{ + u_int8_t *dp; + u_int16_t data; + + dp = *dpp; + data = dp[0] + (dp[1] << 8); + *dpp = dp + 2; + return (data); +} + +static u_int32_t +asl_dump_dworddata(u_int8_t **dpp) +{ + u_int8_t *dp; + u_int32_t data; + + dp = *dpp; + data = dp[0] + (dp[1] << 8) + (dp[2] << 16) + (dp[3] << 24); + *dpp = dp + 4; + return (data); +} + +static u_int8_t * +asl_dump_namestring(u_int8_t **dpp) +{ + u_int8_t *dp; + u_int8_t *name; + + dp = *dpp; + name = dp; + if (dp[0] == '\\') + dp++; + else if (dp[0] == '^') + while (dp[0] == '^') + dp++; + if (dp[0] == 0x00) /* NullName */ + dp++; + else if (dp[0] == 0x2e) /* DualNamePrefix */ + dp += 1 + 4 + 4;/* NameSeg, NameSeg */ + else if (dp[0] == 0x2f) { /* MultiNamePrefix */ + int segcount = dp[1]; + dp += 1 + 1 + segcount * 4; /* segcount * NameSeg */ + } else + dp += 4; /* NameSeg */ + + *dpp = dp; + return (name); +} + +static void +print_namestring(u_int8_t *dp) +{ + + if (dp[0] == '\\') { + putchar(dp[0]); + dp++; + } else if (dp[0] == '^') { + while (dp[0] == '^') { + putchar(dp[0]); + dp++; + } + } + if (dp[0] == 0x00) { /* NullName */ + /* printf("<null>"); */ + dp++; + } else if (dp[0] == 0x2e) { /* DualNamePrefix */ + print_nameseg(dp + 1); + putchar('.'); + print_nameseg(dp + 5); + } else if (dp[0] == 0x2f) { /* MultiNamePrefix */ + int segcount = dp[1]; + int i; + for (i = 0, dp += 2; i < segcount; i++, dp += 4) { + if (i > 0) + putchar('.'); + print_nameseg(dp); + } + } else /* NameSeg */ + print_nameseg(dp); +} + +static void +print_indent(int indent) +{ + int i; + + for (i = 0; i < indent; i++) + printf(" "); +} + +static void +asl_dump_defscope(u_int8_t **dpp, int indent) +{ + u_int8_t *dp; + u_int8_t *start; + u_int8_t *end; + u_int32_t pkglength; + + dp = *dpp; + start = dp; + pkglength = asl_dump_pkglength(&dp); + + printf("Scope("); + asl_dump_termobj(&dp, indent); + printf(") {\n"); + end = start + pkglength; + asl_dump_objectlist(&dp, end, indent + 1); + print_indent(indent); + printf("}"); + + assert(dp == end); + + *dpp = dp; +} + +static void +asl_dump_defbuffer(u_int8_t **dpp, int indent) +{ + u_int8_t *dp; + u_int8_t *start; + u_int8_t *end; + u_int32_t pkglength; + + dp = *dpp; + start = dp; + pkglength = asl_dump_pkglength(&dp); + end = start + pkglength; + printf("Buffer("); + asl_dump_termobj(&dp, indent); + printf(") {"); + while (dp < end) { + printf("0x%x", *dp++); + if (dp < end) + printf(", "); + } + printf(" }"); + + *dpp = dp; +} + +static void +asl_dump_defpackage(u_int8_t **dpp, int indent) +{ + u_int8_t *dp; + u_int8_t *start; + u_int8_t *end; + u_int8_t numelements; + u_int32_t pkglength; + + dp = *dpp; + start = dp; + pkglength = asl_dump_pkglength(&dp); + numelements = asl_dump_bytedata(&dp); + end = start + pkglength; + printf("Package(0x%x) {\n", numelements); + while (dp < end) { + print_indent(indent + 1); + asl_dump_termobj(&dp, indent + 1); + printf(",\n"); + } + + print_indent(indent); + printf("}"); + + dp = end; + + *dpp = dp; +} + +static void +asl_dump_defmethod(u_int8_t **dpp, int indent) +{ + u_int8_t *dp; + u_int8_t *start; + u_int8_t *end; + u_int8_t flags; + u_int32_t pkglength; + + dp = *dpp; + start = dp; + pkglength = asl_dump_pkglength(&dp); + + printf("Method("); + asl_dump_termobj(&dp, indent); + flags = *dp++; + if (flags) { + printf(", %d", flags & 7); + if (flags & 8) { + printf(", Serialized"); + } + } + printf(") {\n"); + end = start + pkglength; + asl_dump_objectlist(&dp, end, indent + 1); + print_indent(indent); + printf("}"); + + assert(dp == end); + + *dpp = dp; +} + + +static void +asl_dump_defopregion(u_int8_t **dpp, int indent) +{ + u_int8_t *dp; + const char *regions[] = { + "SystemMemory", + "SystemIO", + "PCI_Config", + "EmbeddedControl", + "SMBus", + }; + + dp = *dpp; + printf("OperationRegion("); + asl_dump_termobj(&dp, indent); /* Name */ + printf(", %s, ", regions[*dp++]); /* Space */ + asl_dump_termobj(&dp, indent); /* Offset */ + printf(", "); + asl_dump_termobj(&dp, indent); /* Length */ + printf(")"); + + *dpp = dp; +} + +static const char *accessnames[] = { + "AnyAcc", + "ByteAcc", + "WordAcc", + "DWordAcc", + "BlockAcc", + "SMBSendRecvAcc", + "SMBQuickAcc" +}; + +static int +asl_dump_field(u_int8_t **dpp, u_int32_t offset) +{ + u_int8_t *dp; + u_int8_t *name; + u_int8_t access, attribute; + u_int32_t width; + + dp = *dpp; + switch (*dp) { + case '\\': + case '^': + case 'A' ... 'Z': + case '_': + case '.': + name = asl_dump_namestring(&dp); + width = asl_dump_pkglength(&dp); + offset += width; + print_namestring(name); + printf(",\t%d", width); + break; + case 0x00: + dp++; + width = asl_dump_pkglength(&dp); + offset += width; + if ((offset % 8) == 0) { + printf("Offset(0x%x)", offset / 8); + } else { + printf(",\t%d", width); + } + break; + case 0x01: + access = dp[1]; + attribute = dp[2]; + dp += 3; + printf("AccessAs(%s, %d)", accessnames[access], attribute); + break; + } + + *dpp = dp; + return (offset); +} + +static void +asl_dump_fieldlist(u_int8_t **dpp, u_int8_t *end, int indent) +{ + u_int8_t *dp; + u_int32_t offset; + + dp = *dpp; + offset = 0; + while (dp < end) { + print_indent(indent); + offset = asl_dump_field(&dp, offset); + if (dp < end) + printf(",\n"); + else + printf("\n"); + } + + *dpp = dp; +} + +static void +asl_dump_deffield(u_int8_t **dpp, int indent) +{ + u_int8_t *dp; + u_int8_t *start; + u_int8_t *end; + u_int8_t flags; + u_int32_t pkglength; + static const char *lockrules[] = {"NoLock", "Lock"}; + static const char *updaterules[] = {"Preserve", "WriteAsOnes", + "WriteAsZeros", "*Error*"}; + + dp = *dpp; + start = dp; + pkglength = asl_dump_pkglength(&dp); + end = start + pkglength; + + printf("Field("); + asl_dump_termobj(&dp, indent); /* Name */ + flags = asl_dump_bytedata(&dp); + printf(", %s, %s, %s) {\n", + accessnames[flags & 0xf], + lockrules[(flags >> 4) & 1], + updaterules[(flags >> 5) & 3]); + asl_dump_fieldlist(&dp, end, indent + 1); + print_indent(indent); + printf("}"); + + assert(dp == end); + + *dpp = dp; +} + +static void +asl_dump_defindexfield(u_int8_t **dpp, int indent) +{ + u_int8_t *dp; + u_int8_t *start; + u_int8_t *end; + u_int8_t flags; + u_int32_t pkglength; + static const char *lockrules[] = {"NoLock", "Lock"}; + static const char *updaterules[] = {"Preserve", "WriteAsOnes", + "WriteAsZeros", "*Error*"}; + + dp = *dpp; + start = dp; + pkglength = asl_dump_pkglength(&dp); + end = start + pkglength; + + printf("IndexField("); + asl_dump_termobj(&dp, indent); /* Name1 */ + printf(", "); + asl_dump_termobj(&dp, indent); /* Name2 */ + flags = asl_dump_bytedata(&dp); + printf(", %s, %s, %s) {\n", + accessnames[flags & 0xf], + lockrules[(flags >> 4) & 1], + updaterules[(flags >> 5) & 3]); + asl_dump_fieldlist(&dp, end, indent + 1); + print_indent(indent); + printf("}"); + + assert(dp == end); + + *dpp = dp; +} + +static void +asl_dump_defbankfield(u_int8_t **dpp, int indent) +{ + u_int8_t *dp; + u_int8_t *start; + u_int8_t *end; + u_int8_t flags; + u_int32_t pkglength; + static const char *lockrules[] = {"NoLock", "Lock"}; + static const char *updaterules[] = {"Preserve", "WriteAsOnes", + "WriteAsZeros", "*Error*"}; + + dp = *dpp; + start = dp; + pkglength = asl_dump_pkglength(&dp); + end = start + pkglength; + + printf("Field("); + asl_dump_termobj(&dp, indent); /* Name1 */ + printf(", "); + asl_dump_termobj(&dp, indent); /* Name2 */ + printf(", "); + asl_dump_termobj(&dp, indent); /* BankValue */ + flags = asl_dump_bytedata(&dp); + printf(", %s, %s, %s) {\n", + accessnames[flags & 0xf], + lockrules[(flags >> 4) & 1], + updaterules[(flags >> 5) & 3]); + asl_dump_fieldlist(&dp, end, indent + 1); + print_indent(indent); + printf("}"); + + assert(dp == end); + + *dpp = dp; +} + +static void +asl_dump_defdevice(u_int8_t **dpp, int indent) +{ + u_int8_t *dp; + u_int8_t *start; + u_int8_t *end; + u_int32_t pkglength; + + dp = *dpp; + start = dp; + pkglength = asl_dump_pkglength(&dp); + end = start + pkglength; + + printf("Device("); + asl_dump_termobj(&dp, indent); + printf(") {\n"); + asl_dump_objectlist(&dp, end, indent + 1); + print_indent(indent); + printf("}"); + + assert(dp == end); + + *dpp = dp; +} + +static void +asl_dump_defprocessor(u_int8_t **dpp, int indent) +{ + u_int8_t *dp; + u_int8_t *start; + u_int8_t *end; + u_int8_t procid; + u_int8_t pblklen; + u_int32_t pkglength; + u_int32_t pblkaddr; + + dp = *dpp; + start = dp; + pkglength = asl_dump_pkglength(&dp); + end = start + pkglength; + + printf("Processor("); + asl_dump_termobj(&dp, indent); + procid = asl_dump_bytedata(&dp); + pblkaddr = asl_dump_dworddata(&dp); + pblklen = asl_dump_bytedata(&dp); + printf(", %d, 0x%x, 0x%x) {\n", procid, pblkaddr, pblklen); + asl_dump_objectlist(&dp, end, indent + 1); + print_indent(indent); + printf("}"); + + assert(dp == end); + + *dpp = dp; +} + +static void +asl_dump_defpowerres(u_int8_t **dpp, int indent) +{ + u_int8_t *dp; + u_int8_t *start; + u_int8_t *end; + u_int8_t systemlevel; + u_int16_t resourceorder; + u_int32_t pkglength; + + dp = *dpp; + start = dp; + pkglength = asl_dump_pkglength(&dp); + end = start + pkglength; + + printf("PowerResource("); + asl_dump_termobj(&dp, indent); + systemlevel = asl_dump_bytedata(&dp); + resourceorder = asl_dump_worddata(&dp); + printf(", %d, %d) {\n", systemlevel, resourceorder); + asl_dump_objectlist(&dp, end, indent + 1); + print_indent(indent); + printf("}"); + + assert(dp == end); + + *dpp = dp; +} + +static void +asl_dump_defthermalzone(u_int8_t **dpp, int indent) +{ + u_int8_t *dp; + u_int8_t *start; + u_int8_t *end; + u_int32_t pkglength; + + dp = *dpp; + start = dp; + pkglength = asl_dump_pkglength(&dp); + end = start + pkglength; + + printf("ThermalZone("); + asl_dump_termobj(&dp, indent); + printf(") {\n"); + asl_dump_objectlist(&dp, end, indent + 1); + print_indent(indent); + printf("}"); + + assert(dp == end); + + *dpp = dp; +} + +static void +asl_dump_defif(u_int8_t **dpp, int indent) +{ + u_int8_t *dp; + u_int8_t *start; + u_int8_t *end; + u_int32_t pkglength; + + dp = *dpp; + start = dp; + pkglength = asl_dump_pkglength(&dp); + end = start + pkglength; + + printf("If("); + asl_dump_termobj(&dp, indent); + printf(") {\n"); + asl_dump_objectlist(&dp, end, indent + 1); + print_indent(indent); + printf("}"); + + assert(dp == end); + + *dpp = dp; +} + +static void +asl_dump_defelse(u_int8_t **dpp, int indent) +{ + u_int8_t *dp; + u_int8_t *start; + u_int8_t *end; + u_int32_t pkglength; + + dp = *dpp; + start = dp; + pkglength = asl_dump_pkglength(&dp); + end = start + pkglength; + + printf("Else {\n"); + asl_dump_objectlist(&dp, end, indent + 1); + print_indent(indent); + printf("}"); + + assert(dp == end); + + *dpp = dp; +} + +static void +asl_dump_defwhile(u_int8_t **dpp, int indent) +{ + u_int8_t *dp; + u_int8_t *start; + u_int8_t *end; + u_int32_t pkglength; + + dp = *dpp; + start = dp; + pkglength = asl_dump_pkglength(&dp); + end = start + pkglength; + + printf("While("); + asl_dump_termobj(&dp, indent); + printf(") {\n"); + asl_dump_objectlist(&dp, end, indent + 1); + print_indent(indent); + printf("}"); + + assert(dp == end); + + *dpp = dp; +} + +/* + * Public interfaces + */ + +void +asl_dump_termobj(u_int8_t **dpp, int indent) +{ + u_int8_t *dp; + u_int8_t opcode; + const char *matchstr[] = { + "MTR", "MEQ", "MLE", "MLT", "MGE", "MGT", + }; + +#define OPTARG() do { \ + printf(", "); \ + if (*dp == 0x00) { \ + dp++; \ + } else { \ + asl_dump_termobj(&dp, indent); \ + } \ +} while (0) + + dp = *dpp; + opcode = *dp++; + switch (opcode) { + case '\\': + case '^': + case 'A' ... 'Z': + case '_': + case '.': + dp--; + print_namestring(asl_dump_namestring(&dp)); + break; + case 0x0a: /* BytePrefix */ + printf("0x%x", asl_dump_bytedata(&dp)); + break; + case 0x0b: /* WordPrefix */ + printf("0x%04x", asl_dump_worddata(&dp)); + break; + case 0x0c: /* DWordPrefix */ + printf("0x%08x", asl_dump_dworddata(&dp)); + break; + case 0x0d: /* StringPrefix */ + printf("\"%s\"", (const char *) dp); + while (*dp) + dp++; + dp++; /* NUL terminate */ + break; + case 0x00: /* ZeroOp */ + printf("Zero"); + break; + case 0x01: /* OneOp */ + printf("One"); + break; + case 0xff: /* OnesOp */ + printf("Ones"); + break; + case 0x06: /* AliasOp */ + printf("Alias("); + asl_dump_termobj(&dp, indent); + printf(", "); + asl_dump_termobj(&dp, indent); + printf(")"); + break; + case 0x08: /* NameOp */ + printf("Name("); + asl_dump_termobj(&dp, indent); + printf(", "); + asl_dump_termobj(&dp, indent); + printf(")"); + break; + case 0x10: /* ScopeOp */ + asl_dump_defscope(&dp, indent); + break; + case 0x11: /* BufferOp */ + asl_dump_defbuffer(&dp, indent); + break; + case 0x12: /* PackageOp */ + asl_dump_defpackage(&dp, indent); + break; + case 0x14: /* MethodOp */ + asl_dump_defmethod(&dp, indent); + break; + case 0x5b: /* ExtOpPrefix */ + opcode = *dp++; + switch (opcode) { + case 0x01: /* MutexOp */ + printf("Mutex("); + asl_dump_termobj(&dp, indent); + printf(", %d)", *dp++); + break; + case 0x02: /* EventOp */ + printf("Event("); + asl_dump_termobj(&dp, indent); + printf(")"); + break; + case 0x12: /* CondRefOfOp */ + printf("CondRefOf("); + asl_dump_termobj(&dp, indent); + printf(", "); + asl_dump_termobj(&dp, indent); + printf(")"); + break; + case 0x13: /* CreateFieldOp */ + printf("CreateField("); + asl_dump_termobj(&dp, indent); + printf(", "); + asl_dump_termobj(&dp, indent); + printf(", "); + asl_dump_termobj(&dp, indent); + printf(", "); + asl_dump_termobj(&dp, indent); + printf(")"); + break; + case 0x20: /* LoadOp */ + printf("Load("); + asl_dump_termobj(&dp, indent); + printf(", "); + asl_dump_termobj(&dp, indent); + printf(")"); + break; + case 0x21: /* StallOp */ + printf("Stall("); + asl_dump_termobj(&dp, indent); + printf(")"); + break; + case 0x22: /* SleepOp */ + printf("Sleep("); + asl_dump_termobj(&dp, indent); + printf(")"); + break; + case 0x23: /* AcquireOp */ + printf("Acquire("); + asl_dump_termobj(&dp, indent); + printf(", 0x%x)", asl_dump_worddata(&dp)); + break; + case 0x24: /* SignalOp */ + printf("Signal("); + asl_dump_termobj(&dp, indent); + printf(")"); + break; + case 0x25: /* WaitOp */ + printf("Wait("); + asl_dump_termobj(&dp, indent); + printf(", "); + asl_dump_termobj(&dp, indent); + printf(")"); + break; + case 0x26: /* ResetOp */ + printf("Reset("); + asl_dump_termobj(&dp, indent); + printf(")"); + break; + case 0x27: /* ReleaseOp */ + printf("Release("); + asl_dump_termobj(&dp, indent); + printf(")"); + break; + case 0x28: /* FromBCDOp */ + printf("FromBCD("); + asl_dump_termobj(&dp, indent); + printf(", "); + asl_dump_termobj(&dp, indent); + printf(")"); + break; + case 0x29: /* ToBCDOp */ + printf("ToBCD("); + asl_dump_termobj(&dp, indent); + OPTARG(); + printf(")"); + break; + case 0x2a: /* UnloadOp */ + printf("Unload("); + asl_dump_termobj(&dp, indent); + printf(")"); + break; + case 0x30: + printf("Revision"); + break; + case 0x31: + printf("Debug"); + break; + case 0x32: /* FatalOp */ + printf("Fatal("); + printf("0x%x, ", asl_dump_bytedata(&dp)); + printf("0x%x, ", asl_dump_dworddata(&dp)); + asl_dump_termobj(&dp, indent); + printf(")"); + break; + case 0x80: /* OpRegionOp */ + asl_dump_defopregion(&dp, indent); + break; + case 0x81: /* FieldOp */ + asl_dump_deffield(&dp, indent); + break; + case 0x82: /* DeviceOp */ + asl_dump_defdevice(&dp, indent); + break; + case 0x83: /* ProcessorOp */ + asl_dump_defprocessor(&dp, indent); + break; + case 0x84: /* PowerResOp */ + asl_dump_defpowerres(&dp, indent); + break; + case 0x85: /* ThermalZoneOp */ + asl_dump_defthermalzone(&dp, indent); + break; + case 0x86: /* IndexFieldOp */ + asl_dump_defindexfield(&dp, indent); + break; + case 0x87: /* BankFieldOp */ + asl_dump_defbankfield(&dp, indent); + break; + default: + errx(1, "strange opcode 0x5b, 0x%x\n", opcode); + } + break; + case 0x68 ... 0x6e: /* ArgN */ + printf("Arg%d", opcode - 0x68); + break; + case 0x60 ... 0x67: + printf("Local%d", opcode - 0x60); + break; + case 0x70: /* StoreOp */ + printf("Store("); + asl_dump_termobj(&dp, indent); + printf(", "); + asl_dump_termobj(&dp, indent); + printf(")"); + break; + case 0x71: /* RefOfOp */ + printf("RefOf("); + asl_dump_termobj(&dp, indent); + printf(")"); + break; + case 0x72: /* AddOp */ + printf("Add("); + asl_dump_termobj(&dp, indent); + printf(", "); + asl_dump_termobj(&dp, indent); + OPTARG(); + printf(")"); + break; + case 0x73: /* ConcatOp */ + printf("Concat("); + asl_dump_termobj(&dp, indent); + printf(", "); + asl_dump_termobj(&dp, indent); + printf(", "); + asl_dump_termobj(&dp, indent); + printf(")"); + break; + case 0x74: /* SubtractOp */ + printf("Subtract("); + asl_dump_termobj(&dp, indent); + printf(", "); + asl_dump_termobj(&dp, indent); + OPTARG(); + printf(")"); + break; + case 0x75: /* IncrementOp */ + printf("Increment("); + asl_dump_termobj(&dp, indent); + printf(")"); + break; + case 0x76: /* DecrementOp */ + printf("Decrement("); + asl_dump_termobj(&dp, indent); + printf(")"); + break; + case 0x77: /* MultiplyOp */ + printf("Multiply("); + asl_dump_termobj(&dp, indent); + printf(", "); + asl_dump_termobj(&dp, indent); + OPTARG(); + printf(")"); + break; + case 0x78: /* DivideOp */ + printf("Divide("); + asl_dump_termobj(&dp, indent); + printf(", "); + asl_dump_termobj(&dp, indent); + OPTARG(); + OPTARG(); + printf(")"); + break; + case 0x79: /* ShiftLeftOp */ + printf("ShiftLeft("); + asl_dump_termobj(&dp, indent); + printf(", "); + asl_dump_termobj(&dp, indent); + OPTARG(); + printf(")"); + break; + case 0x7a: /* ShiftRightOp */ + printf("ShiftRight("); + asl_dump_termobj(&dp, indent); + printf(", "); + asl_dump_termobj(&dp, indent); + OPTARG(); + printf(")"); + break; + case 0x7b: /* AndOp */ + printf("And("); + asl_dump_termobj(&dp, indent); + printf(", "); + asl_dump_termobj(&dp, indent); + OPTARG(); + printf(")"); + break; + case 0x7c: /* NAndOp */ + printf("NAnd("); + asl_dump_termobj(&dp, indent); + printf(", "); + asl_dump_termobj(&dp, indent); + OPTARG(); + printf(")"); + break; + case 0x7d: /* OrOp */ + printf("Or("); + asl_dump_termobj(&dp, indent); + printf(", "); + asl_dump_termobj(&dp, indent); + OPTARG(); + printf(")"); + break; + case 0x7e: /* NOrOp */ + printf("NOr("); + asl_dump_termobj(&dp, indent); + printf(", "); + asl_dump_termobj(&dp, indent); + OPTARG(); + printf(")"); + break; + case 0x7f: /* XOrOp */ + printf("XOr("); + asl_dump_termobj(&dp, indent); + printf(", "); + asl_dump_termobj(&dp, indent); + OPTARG(); + printf(")"); + break; + case 0x80: /* NotOp */ + printf("Not("); + asl_dump_termobj(&dp, indent); + OPTARG(); + printf(")"); + break; + case 0x81: /* FindSetLeftBitOp */ + printf("FindSetLeftBit("); + asl_dump_termobj(&dp, indent); + printf(", "); + asl_dump_termobj(&dp, indent); + printf(")"); + break; + case 0x82: /* FindSetRightBitOp */ + printf("FindSetRightBit("); + asl_dump_termobj(&dp, indent); + printf(", "); + asl_dump_termobj(&dp, indent); + printf(")"); + break; + case 0x83: /* DerefOp */ + printf("DerefOf("); + asl_dump_termobj(&dp, indent); + printf(")"); + break; + case 0x86: /* NotifyOp */ + printf("Notify("); + asl_dump_termobj(&dp, indent); + printf(", "); + asl_dump_termobj(&dp, indent); + printf(")"); + break; + case 0x87: /* SizeOfOp */ + printf("Sizeof("); + asl_dump_termobj(&dp, indent); + printf(")"); + break; + case 0x88: /* IndexOp */ + printf("Index("); + asl_dump_termobj(&dp, indent); + printf(", "); + asl_dump_termobj(&dp, indent); + OPTARG(); + printf(")"); + break; + case 0x89: /* MatchOp */ + printf("Match("); + asl_dump_termobj(&dp, indent); + printf(", %s, ", matchstr[*dp++]); + asl_dump_termobj(&dp, indent); + printf(", %s, ", matchstr[*dp++]); + asl_dump_termobj(&dp, indent); + printf(", "); + asl_dump_termobj(&dp, indent); + printf(")"); + break; + case 0x8a: /* CreateDWordFieldOp */ + printf("CreateDWordField("); + asl_dump_termobj(&dp, indent); + printf(", "); + asl_dump_termobj(&dp, indent); + printf(", "); + asl_dump_termobj(&dp, indent); + printf(")"); + break; + case 0x8b: /* CreateWordFieldOp */ + printf("CreateWordField("); + asl_dump_termobj(&dp, indent); + printf(", "); + asl_dump_termobj(&dp, indent); + printf(", "); + asl_dump_termobj(&dp, indent); + printf(")"); + break; + case 0x8c: /* CreateByteFieldOp */ + printf("CreateByteField("); + asl_dump_termobj(&dp, indent); + printf(", "); + asl_dump_termobj(&dp, indent); + printf(", "); + asl_dump_termobj(&dp, indent); + printf(")"); + break; + case 0x8d: /* CreateBitFieldOp */ + printf("CreateBitField("); + asl_dump_termobj(&dp, indent); + printf(", "); + asl_dump_termobj(&dp, indent); + printf(", "); + asl_dump_termobj(&dp, indent); + printf(")"); + break; + case 0x8e: /* ObjectTypeOp */ + printf("ObjectType("); + asl_dump_termobj(&dp, indent); + printf(")"); + break; + case 0x90: + printf("LAnd("); + asl_dump_termobj(&dp, indent); + printf(", "); + asl_dump_termobj(&dp, indent); + printf(")"); + break; + case 0x91: + printf("LOr("); + asl_dump_termobj(&dp, indent); + printf(", "); + asl_dump_termobj(&dp, indent); + printf(")"); + break; + case 0x92: + printf("LNot("); + asl_dump_termobj(&dp, indent); + printf(")"); + break; + case 0x93: + printf("LEqual("); + asl_dump_termobj(&dp, indent); + printf(", "); + asl_dump_termobj(&dp, indent); + printf(")"); + break; + case 0x94: + printf("LGreater("); + asl_dump_termobj(&dp, indent); + printf(", "); + asl_dump_termobj(&dp, indent); + printf(")"); + break; + case 0x95: + printf("LLess("); + asl_dump_termobj(&dp, indent); + printf(", "); + asl_dump_termobj(&dp, indent); + printf(")"); + break; + case 0xa0: /* IfOp */ + asl_dump_defif(&dp, indent); + break; + case 0xa1: /* ElseOp */ + asl_dump_defelse(&dp, indent); + break; + case 0xa2: /* WhileOp */ + asl_dump_defwhile(&dp, indent); + break; + case 0xa3: /* NoopOp */ + printf("Noop"); + break; + case 0xa5: /* BreakOp */ + printf("Break"); + break; + case 0xa4: /* ReturnOp */ + printf("Return("); + asl_dump_termobj(&dp, indent); + printf(")"); + break; + case 0xcc: /* BreakPointOp */ + printf("BreakPoint"); + break; + default: + errx(1, "strange opcode 0x%x\n", opcode); + } + + *dpp = dp; +} + +void +asl_dump_objectlist(u_int8_t **dpp, u_int8_t *end, int indent) +{ + u_int8_t *dp; + + dp = *dpp; + while (dp < end) { + print_indent(indent); + asl_dump_termobj(&dp, indent); + printf("\n"); + } + + *dpp = dp; +} |