1 /* $NetBSD: amldb.c,v 1.1 2007/01/14 04:36:13 christos Exp $ */
4 * Copyright (c) 1999 Mitsuru IWASAKI <iwasaki@FreeBSD.org>
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
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
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>
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>
55 int regdump_enabled
= 0;
56 int memstat_enabled
= 0;
57 int showtree_enabled
= 0;
59 static void aml_init_namespace(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");
76 load_dsdt(const char *dsdtfile
)
78 struct aml_environ env
;
83 printf("Loading %s...", dsdtfile
);
85 fd
= open(dsdtfile
, O_RDONLY
, 0);
90 if (fstat(fd
, &sb
) == -1) {
94 if ((code
= mmap(NULL
, sb
.st_size
, PROT_READ
, MAP_PRIVATE
, fd
, 0)) == NULL
) {
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
;
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
);
118 env
.end
= code
+ sb
.st_size
;
122 aml_debug
= 1; /* debug print enabled */
124 if (showtree_enabled
== 1) {
125 aml_showtree(env
.curname
, 0);
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
);
149 usage(const char *progname
)
152 printf("usage: %s [-d] [-s] [-t] [-h] dsdt_files...\n", progname
);
157 main(int argc
, char *argv
[])
163 while ((c
= getopt(argc
, argv
, "dsth")) != -1) {
172 showtree_enabled
= 1;
186 for (i
= 0; i
< argc
; i
++) {