Expand PMF_FN_* macros.
[netbsd-mini2440.git] / usr.sbin / acpitools / amldb / amldb.c
blob5ecc21cd41361ea67a0fdf50e4cd64809f408a39
1 /* $NetBSD: amldb.c,v 1.1 2007/01/14 04:36:13 christos Exp $ */
3 /*-
4 * Copyright (c) 1999 Mitsuru IWASAKI <iwasaki@FreeBSD.org>
5 * All rights reserved.
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.
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.
28 * Id: amldb.c,v 1.8 2000/08/08 14:12:24 iwasaki Exp
29 * $FreeBSD: src/usr.sbin/acpi/amldb/amldb.c,v 1.3 2001/10/22 17:25:32 iwasaki Exp $
31 #include <sys/cdefs.h>
32 __RCSID("$NetBSD: amldb.c,v 1.1 2007/01/14 04:36:13 christos Exp $");
34 #include <sys/param.h>
35 #include <sys/mman.h>
36 #include <sys/stat.h>
38 #include <acpi_common.h>
39 #include <aml/aml_amlmem.h>
40 #include <aml/aml_common.h>
41 #include <aml/aml_env.h>
42 #include <aml/aml_parse.h>
43 #include <aml/aml_region.h>
45 #include <assert.h>
46 #include <err.h>
47 #include <fcntl.h>
48 #include <stdio.h>
49 #include <string.h>
50 #include <unistd.h>
51 #include <stdlib.h>
53 #include "debug.h"
55 int regdump_enabled = 0;
56 int memstat_enabled = 0;
57 int showtree_enabled = 0;
59 static void aml_init_namespace(void);
61 void
62 aml_init_namespace(void)
64 struct aml_environ env;
65 struct aml_name *newname;
67 aml_new_name_group((void *)AML_NAME_GROUP_OS_DEFINED);
68 env.curname = aml_get_rootname();
69 newname = aml_create_name(&env, (const u_int8_t *)"\\_OS_");
70 newname->property = aml_alloc_object(aml_t_string, NULL);
71 newname->property->str.needfree = 0;
72 newname->property->str.string = __UNCONST("Microsoft Windows NT");
75 static int
76 load_dsdt(const char *dsdtfile)
78 struct aml_environ env;
79 u_int8_t *code;
80 struct stat sb;
81 int fd;
83 printf("Loading %s...", dsdtfile);
85 fd = open(dsdtfile, O_RDONLY, 0);
86 if (fd == -1) {
87 perror("open");
88 exit(-1);
90 if (fstat(fd, &sb) == -1) {
91 perror("fstat");
92 exit(-1);
94 if ((code = mmap(NULL, sb.st_size, PROT_READ, MAP_PRIVATE, fd, 0)) == NULL) {
95 perror("mmap");
96 exit(-1);
98 aml_init_namespace();
100 aml_new_name_group(code);
101 bzero(&env, sizeof(env));
103 #define SIZEOF_SDT_HDR 36 /* struct size except body */
104 if (strncmp((const char *)code, "DSDT", 4) == 0) {
105 env.dp = code + SIZEOF_SDT_HDR;
106 } else {
107 env.dp = code;
109 env.end = code + sb.st_size;
110 env.curname = aml_get_rootname();
112 aml_local_stack_push(aml_local_stack_create());
113 aml_parse_objectlist(&env, 0);
114 aml_local_stack_delete(aml_local_stack_pop());
116 assert(env.dp == env.end);
117 env.dp = code;
118 env.end = code + sb.st_size;
120 printf("done\n");
122 aml_debug = 1; /* debug print enabled */
124 if (showtree_enabled == 1) {
125 aml_showtree(env.curname, 0);
127 do {
128 aml_dbgr(&env, &env);
129 } while (env.stat != aml_stat_panic);
131 aml_debug = 0; /* debug print disabled */
133 if (regdump_enabled == 1) {
134 aml_simulation_regdump("region.dmp");
136 while (name_group_list->id != AML_NAME_GROUP_ROOT) {
137 aml_delete_name_group(name_group_list);
140 if (memstat_enabled == 1) {
141 memman_statistics(aml_memman);
143 memman_freeall(aml_memman);
145 return (0);
148 static void
149 usage(const char *progname)
152 printf("usage: %s [-d] [-s] [-t] [-h] dsdt_files...\n", progname);
153 exit(1);
157 main(int argc, char *argv[])
159 char c, *progname;
160 int i;
162 progname = argv[0];
163 while ((c = getopt(argc, argv, "dsth")) != -1) {
164 switch (c) {
165 case 'd':
166 regdump_enabled = 1;
167 break;
168 case 's':
169 memstat_enabled = 1;
170 break;
171 case 't':
172 showtree_enabled = 1;
173 break;
174 case 'h':
175 default:
176 usage(progname);
177 /* NOTREACHED */
180 argc -= optind;
181 argv += optind;
183 if (argc == 0) {
184 usage(progname);
186 for (i = 0; i < argc; i++) {
187 load_dsdt(argv[i]);
190 return (0);