xref: /netbsd-src/usr.sbin/acpitools/aml/aml_parse.c (revision a41f6947a1dbcc459409ad07cbf69e8ce0688663)
1*a41f6947Sandvar /*	$NetBSD: aml_parse.c,v 1.6 2022/03/23 13:06:06 andvar Exp $	*/
253e202c1Schristos 
353e202c1Schristos /*-
453e202c1Schristos  * Copyright (c) 1999 Doug Rabson
553e202c1Schristos  * Copyright (c) 1999, 2000 Mitsuru IWASAKI <iwasaki@FreeBSD.org>
653e202c1Schristos  * All rights reserved.
753e202c1Schristos  *
853e202c1Schristos  * Redistribution and use in source and binary forms, with or without
953e202c1Schristos  * modification, are permitted provided that the following conditions
1053e202c1Schristos  * are met:
1153e202c1Schristos  * 1. Redistributions of source code must retain the above copyright
1253e202c1Schristos  *    notice, this list of conditions and the following disclaimer.
1353e202c1Schristos  * 2. Redistributions in binary form must reproduce the above copyright
1453e202c1Schristos  *    notice, this list of conditions and the following disclaimer in the
1553e202c1Schristos  *    documentation and/or other materials provided with the distribution.
1653e202c1Schristos  *
1753e202c1Schristos  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
1853e202c1Schristos  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
1953e202c1Schristos  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2053e202c1Schristos  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
2153e202c1Schristos  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
2253e202c1Schristos  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2353e202c1Schristos  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2453e202c1Schristos  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
2553e202c1Schristos  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
2653e202c1Schristos  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
2753e202c1Schristos  * SUCH DAMAGE.
2853e202c1Schristos  *
2953e202c1Schristos  *	Id: aml_parse.c,v 1.32 2000/08/12 15:20:45 iwasaki Exp
3053e202c1Schristos  *	$FreeBSD: src/usr.sbin/acpi/amldb/aml/aml_parse.c,v 1.7 2001/10/23 14:54:15 takawata Exp $
3153e202c1Schristos  */
3253e202c1Schristos #include <sys/cdefs.h>
33*a41f6947Sandvar __RCSID("$NetBSD: aml_parse.c,v 1.6 2022/03/23 13:06:06 andvar Exp $");
3453e202c1Schristos 
3553e202c1Schristos #include <sys/param.h>
3653e202c1Schristos 
3753e202c1Schristos #include <acpi_common.h>
3853e202c1Schristos #include <aml/aml_amlmem.h>
3953e202c1Schristos #include <aml/aml_common.h>
4053e202c1Schristos #include <aml/aml_env.h>
4153e202c1Schristos #include <aml/aml_evalobj.h>
4253e202c1Schristos #include <aml/aml_name.h>
4353e202c1Schristos #include <aml/aml_obj.h>
4453e202c1Schristos #include <aml/aml_parse.h>
4553e202c1Schristos #include <aml/aml_status.h>
4653e202c1Schristos #include <aml/aml_store.h>
4753e202c1Schristos 
4853e202c1Schristos #ifndef _KERNEL
4953e202c1Schristos #include <sys/stat.h>
5053e202c1Schristos #include <sys/mman.h>
5153e202c1Schristos 
5253e202c1Schristos #include <assert.h>
5353e202c1Schristos #include <err.h>
5453e202c1Schristos #include <fcntl.h>
5553e202c1Schristos #include <stdio.h>
5653e202c1Schristos #include <stdlib.h>
5753e202c1Schristos #include <string.h>
5853e202c1Schristos #include <unistd.h>
5953e202c1Schristos 
6053e202c1Schristos #include "debug.h"
6153e202c1Schristos #else /* _KERNEL */
6253e202c1Schristos #include <sys/systm.h>
6353e202c1Schristos #include <sys/bus.h>
6453e202c1Schristos #include <dev/acpi/acpireg.h>
6553e202c1Schristos #include <dev/acpi/acpivar.h>
6653e202c1Schristos #ifndef ACPI_NO_OSDFUNC_INLINE
6753e202c1Schristos #include <machine/acpica_osd.h>
6853e202c1Schristos #endif
6953e202c1Schristos #endif /* !_KERNEL */
7053e202c1Schristos 
7153e202c1Schristos static int		 findsetleftbit(int num);
7253e202c1Schristos static int		 findsetrightbit(int num);
7353e202c1Schristos static int		 frombcd(int num);
7453e202c1Schristos static int		 tobcd(int num);
7553e202c1Schristos 
7653e202c1Schristos static u_int32_t	 aml_parse_pkglength(struct aml_environ *env);
7753e202c1Schristos static u_int8_t		 aml_parse_bytedata(struct aml_environ *env);
7853e202c1Schristos static u_int16_t	 aml_parse_worddata(struct aml_environ *env);
7953e202c1Schristos static u_int32_t	 aml_parse_dworddata(struct aml_environ *env);
8053e202c1Schristos static u_int8_t		*aml_parse_namestring(struct aml_environ *env);
8153e202c1Schristos static void		 aml_parse_defscope(struct aml_environ *env,
8253e202c1Schristos 					    int indent);
8353e202c1Schristos static union aml_object	*aml_parse_defbuffer(struct aml_environ *env,
8453e202c1Schristos 					     int indent);
8553e202c1Schristos static struct aml_name	*aml_parse_concat_number(struct aml_environ *env,
8653e202c1Schristos 						 int num1, int indent);
8753e202c1Schristos static struct aml_name	*aml_parse_concat_buffer(struct aml_environ *env,
8853e202c1Schristos 						 union aml_object *obj,
8953e202c1Schristos 						 int indent);
9053e202c1Schristos static struct aml_name	*aml_parse_concat_string(struct aml_environ *env,
9153e202c1Schristos 						 union aml_object *obj,
9253e202c1Schristos 						 int indent);
9353e202c1Schristos static struct aml_name	*aml_parse_concatop(struct aml_environ *env,
9453e202c1Schristos 					    int indent);
9553e202c1Schristos static union aml_object	*aml_parse_defpackage(struct aml_environ *env,
9653e202c1Schristos 					      int indent);
9753e202c1Schristos static void		 aml_parse_defmethod(struct aml_environ *env,
9853e202c1Schristos 					     int indent);
9953e202c1Schristos static void		 aml_parse_defopregion(struct aml_environ *env,
10053e202c1Schristos 					       int indent);
10153e202c1Schristos static int		 aml_parse_field(struct aml_environ *env,
10253e202c1Schristos 					 struct aml_field *template);
10353e202c1Schristos static void		 aml_parse_fieldlist(struct aml_environ *env,
10453e202c1Schristos 					     struct aml_field *template,
10553e202c1Schristos 					     int indent);
10653e202c1Schristos static void		 aml_parse_deffield(struct aml_environ *env,
10753e202c1Schristos 					    int indent);
10853e202c1Schristos static void		 aml_parse_defindexfield(struct aml_environ *env,
10953e202c1Schristos 						 int indent);
11053e202c1Schristos static void		 aml_parse_defbankfield(struct aml_environ *env,
11153e202c1Schristos 						int indent);
11253e202c1Schristos static void		 aml_parse_defdevice(struct aml_environ *env,
11353e202c1Schristos 					     int indent);
11453e202c1Schristos static void		 aml_parse_defprocessor(struct aml_environ *env,
11553e202c1Schristos 						int indent);
11653e202c1Schristos static void		 aml_parse_defpowerres(struct aml_environ *env,
11753e202c1Schristos 					       int indent);
11853e202c1Schristos static void		 aml_parse_defthermalzone(struct aml_environ *env,
11953e202c1Schristos 						  int indent);
12053e202c1Schristos static struct aml_name	*aml_parse_defelse(struct aml_environ *env,
12153e202c1Schristos 					   int indent, int num);
12253e202c1Schristos static struct aml_name	*aml_parse_defif(struct aml_environ *env,
12353e202c1Schristos 					 int indent);
12453e202c1Schristos static struct aml_name	*aml_parse_defwhile(struct aml_environ *env,
12553e202c1Schristos 					    int indent);
12653e202c1Schristos static void		 aml_parse_defmutex(struct aml_environ *env,
12753e202c1Schristos 					    int indent);
12853e202c1Schristos static void		 aml_createfield_generic(struct aml_environ *env,
12953e202c1Schristos 						 union aml_object *srcbuf,
13053e202c1Schristos 						 int idx, int len,
13153e202c1Schristos 						 char *newname);
13253e202c1Schristos static void		 aml_parse_defcreatefield(struct aml_environ *env,
13353e202c1Schristos 						  int indent);
13453e202c1Schristos 
13553e202c1Schristos static int
findsetleftbit(int num)13653e202c1Schristos findsetleftbit(int num)
13753e202c1Schristos {
13853e202c1Schristos 	int	i, filter;
13953e202c1Schristos 
14053e202c1Schristos 	filter = 0;
14153e202c1Schristos 	for (i = 0; i < 32; i++) {
14253e202c1Schristos 		filter = filter >> 1;
14353e202c1Schristos 		filter |= 1 << 31;
14453e202c1Schristos 		if (filter & num) {
14553e202c1Schristos 			break;
14653e202c1Schristos 		}
14753e202c1Schristos 	}
14853e202c1Schristos 	i = (i == 32) ? 0 : i + 1;
14953e202c1Schristos 	return (i);
15053e202c1Schristos }
15153e202c1Schristos 
15253e202c1Schristos static int
findsetrightbit(int num)15353e202c1Schristos findsetrightbit(int num)
15453e202c1Schristos {
15553e202c1Schristos 	int	i, filter;
15653e202c1Schristos 
15753e202c1Schristos 	filter = 0;
15853e202c1Schristos 	for (i = 0; i < 32; i++) {
15953e202c1Schristos 		filter = filter << 1;
16053e202c1Schristos 		filter |= 1;
16153e202c1Schristos 		if (filter & num) {
16253e202c1Schristos 			break;
16353e202c1Schristos 		}
16453e202c1Schristos 	}
16553e202c1Schristos 	i = (i == 32) ? 0 : i + 1;
16653e202c1Schristos 	return (i);
16753e202c1Schristos }
16853e202c1Schristos 
16953e202c1Schristos static int
frombcd(int num)17053e202c1Schristos frombcd(int num)
17153e202c1Schristos {
17253e202c1Schristos 	int	res, factor;
17353e202c1Schristos 
17453e202c1Schristos 	res = 0;
17553e202c1Schristos 	factor = 1;
17653e202c1Schristos 	while (num != 0) {
17753e202c1Schristos 		res += ((num & 0xf) * factor);
17853e202c1Schristos 		num = num / 16;
17953e202c1Schristos 		factor *= 10;
18053e202c1Schristos 	}
18153e202c1Schristos 	return (res);
18253e202c1Schristos }
18353e202c1Schristos 
18453e202c1Schristos static int
tobcd(int num)18553e202c1Schristos tobcd(int num)
18653e202c1Schristos {
18753e202c1Schristos 	int	res, factor;
18853e202c1Schristos 
18953e202c1Schristos 	res = 0;
19053e202c1Schristos 	factor = 1;
19153e202c1Schristos 	while (num != 0) {
19253e202c1Schristos 		res += ((num % 10) * factor);
19353e202c1Schristos 		num = num / 10;
19453e202c1Schristos 		factor *= 16;
19553e202c1Schristos 	}
19653e202c1Schristos 	return (res);
19753e202c1Schristos }
19853e202c1Schristos 
19953e202c1Schristos static u_int32_t
aml_parse_pkglength(struct aml_environ * env)20053e202c1Schristos aml_parse_pkglength(struct aml_environ *env)
20153e202c1Schristos {
20253e202c1Schristos 	u_int8_t	*dp;
20353e202c1Schristos 	u_int32_t	pkglength;
20453e202c1Schristos 
20553e202c1Schristos 	dp = env->dp;
20653e202c1Schristos 	pkglength = *dp++;
20753e202c1Schristos 	switch (pkglength >> 6) {
20853e202c1Schristos 	case 0:
20953e202c1Schristos 		break;
21053e202c1Schristos 	case 1:
21153e202c1Schristos 		pkglength = (pkglength & 0xf) + (dp[0] << 4);
21253e202c1Schristos 		dp += 1;
21353e202c1Schristos 		break;
21453e202c1Schristos 	case 2:
21553e202c1Schristos 		pkglength = (pkglength & 0xf) + (dp[0] << 4) + (dp[1] << 12);
21653e202c1Schristos 		dp += 2;
21753e202c1Schristos 		break;
21853e202c1Schristos 	case 3:
21953e202c1Schristos 		pkglength = (pkglength & 0xf)
22053e202c1Schristos 		    + (dp[0] << 4) + (dp[1] << 12) + (dp[2] << 20);
22153e202c1Schristos 		dp += 3;
22253e202c1Schristos 		break;
22353e202c1Schristos 	}
22453e202c1Schristos 
22553e202c1Schristos 	env->dp = dp;
22653e202c1Schristos 	return (pkglength);
22753e202c1Schristos }
22853e202c1Schristos 
22953e202c1Schristos static u_int8_t
aml_parse_bytedata(struct aml_environ * env)23053e202c1Schristos aml_parse_bytedata(struct aml_environ *env)
23153e202c1Schristos {
23253e202c1Schristos 	u_int8_t	data;
23353e202c1Schristos 
23453e202c1Schristos 	data = env->dp[0];
23553e202c1Schristos 	env->dp++;
23653e202c1Schristos 	return (data);
23753e202c1Schristos }
23853e202c1Schristos 
23953e202c1Schristos static u_int16_t
aml_parse_worddata(struct aml_environ * env)24053e202c1Schristos aml_parse_worddata(struct aml_environ *env)
24153e202c1Schristos {
24253e202c1Schristos 	u_int16_t	data;
24353e202c1Schristos 
24453e202c1Schristos 	data = env->dp[0] + (env->dp[1] << 8);
24553e202c1Schristos 	env->dp += 2;
24653e202c1Schristos 	return (data);
24753e202c1Schristos }
24853e202c1Schristos 
24953e202c1Schristos static u_int32_t
aml_parse_dworddata(struct aml_environ * env)25053e202c1Schristos aml_parse_dworddata(struct aml_environ *env)
25153e202c1Schristos {
25253e202c1Schristos 	u_int32_t	data;
25353e202c1Schristos 
25453e202c1Schristos 	data = env->dp[0] + (env->dp[1] << 8) +
25553e202c1Schristos 	    (env->dp[2] << 16) + (env->dp[3] << 24);
25653e202c1Schristos 	env->dp += 4;
25753e202c1Schristos 	return (data);
25853e202c1Schristos }
25953e202c1Schristos 
26053e202c1Schristos static u_int8_t *
aml_parse_namestring(struct aml_environ * env)26153e202c1Schristos aml_parse_namestring(struct aml_environ *env)
26253e202c1Schristos {
26353e202c1Schristos 	u_int8_t	*name;
26453e202c1Schristos 	int		segcount;
26553e202c1Schristos 
26653e202c1Schristos 	name = env->dp;
26753e202c1Schristos 	if (env->dp[0] == '\\')
26853e202c1Schristos 		env->dp++;
26953e202c1Schristos 	else if (env->dp[0] == '^')
27053e202c1Schristos 		while (env->dp[0] == '^')
27153e202c1Schristos 			env->dp++;
27253e202c1Schristos 	if (env->dp[0] == 0x00)	/* NullName */
27353e202c1Schristos 		env->dp++;
27453e202c1Schristos 	else if (env->dp[0] == 0x2e)	/* DualNamePrefix */
27553e202c1Schristos 		env->dp += 1 + 4 + 4;	/* NameSeg, NameSeg */
27653e202c1Schristos 	else if (env->dp[0] == 0x2f) {	/* MultiNamePrefix */
27753e202c1Schristos 		segcount = env->dp[1];
27853e202c1Schristos 		env->dp += 1 + 1 + segcount * 4;	/* segcount * NameSeg */
27953e202c1Schristos 	} else
28053e202c1Schristos 		env->dp += 4;	/* NameSeg */
28153e202c1Schristos 
28253e202c1Schristos 	return (name);
28353e202c1Schristos }
28453e202c1Schristos 
28553e202c1Schristos struct aml_name *
aml_parse_objectlist(struct aml_environ * env,int indent)28653e202c1Schristos aml_parse_objectlist(struct aml_environ *env, int indent)
28753e202c1Schristos {
28853e202c1Schristos 	union	aml_object *obj;
28953e202c1Schristos 
29053e202c1Schristos 	obj = NULL;
29153e202c1Schristos 	while (env->dp < env->end) {
29253e202c1Schristos 		aml_print_indent(indent);
29353e202c1Schristos 		obj = aml_eval_name(env, aml_parse_termobj(env, indent));
29453e202c1Schristos 		AML_DEBUGPRINT("\n");
29553e202c1Schristos 		if (env->stat == aml_stat_step) {
29653e202c1Schristos 			AML_DEBUGGER(env, env);
29753e202c1Schristos 			continue;
29853e202c1Schristos 		}
29953e202c1Schristos 		if (env->stat != aml_stat_none) {
30053e202c1Schristos 			env->tempname.property = obj;
30153e202c1Schristos 			return (&env->tempname);
30253e202c1Schristos 		}
30353e202c1Schristos 	}
30453e202c1Schristos 	return (NULL);
30553e202c1Schristos }
30653e202c1Schristos 
30753e202c1Schristos #define AML_CREATE_NAME(amlname, env, namestr, ret) do {		\
30853e202c1Schristos 	amlname = aml_create_name(env, namestr);			\
30953e202c1Schristos 	if (env->stat == aml_stat_panic)				\
31053e202c1Schristos 		return ret;						\
31153e202c1Schristos } while(0)
31253e202c1Schristos 
31353e202c1Schristos #define AML_COPY_OBJECT(dest, env, src, ret) do {			\
31453e202c1Schristos 	dest = aml_copy_object(env, src);				\
31553e202c1Schristos 	if (dest == NULL) {						\
31653e202c1Schristos 		env->stat = aml_stat_panic;				\
31753e202c1Schristos 		return ret;						\
31853e202c1Schristos 	}								\
31953e202c1Schristos } while(0)
32053e202c1Schristos 
32153e202c1Schristos #define AML_ALLOC_OBJECT(dest, env, type, ret) do {			\
32253e202c1Schristos 	dest = aml_alloc_object(type, NULL);				\
32353e202c1Schristos 	if (dest == NULL) {						\
32453e202c1Schristos 		env->stat= aml_stat_panic;				\
32553e202c1Schristos 		return ret;						\
32653e202c1Schristos 	}								\
32753e202c1Schristos } while(0)
32853e202c1Schristos 
32953e202c1Schristos static void
aml_parse_defscope(struct aml_environ * env,int indent)33053e202c1Schristos aml_parse_defscope(struct aml_environ *env, int indent)
33153e202c1Schristos {
33253e202c1Schristos 	u_int8_t	*start, *end, *oend;
33353e202c1Schristos 	u_int8_t	*name;
33453e202c1Schristos 	u_int32_t	pkglength;
33553e202c1Schristos 	struct	aml_name *oname;
33653e202c1Schristos 
33753e202c1Schristos 	start = env->dp;
33853e202c1Schristos 	pkglength = aml_parse_pkglength(env);
33953e202c1Schristos 
34053e202c1Schristos 	AML_DEBUGPRINT("Scope(");
34153e202c1Schristos 	name = aml_parse_namestring(env);
34253e202c1Schristos 	aml_print_namestring(name);
34353e202c1Schristos 	AML_DEBUGPRINT(") {\n");
34453e202c1Schristos 	oname = env->curname;
34553e202c1Schristos 	AML_CREATE_NAME(env->curname, env, name,);
34653e202c1Schristos 	oend = env->end;
34753e202c1Schristos 	env->end = end = start + pkglength;
34853e202c1Schristos 	aml_parse_objectlist(env, indent + 1);
34953e202c1Schristos 	aml_print_indent(indent);
35053e202c1Schristos 	AML_DEBUGPRINT("}");
35153e202c1Schristos 	AML_SYSASSERT(env->dp == env->end);
35253e202c1Schristos 	env->dp = end;
35353e202c1Schristos 	env->end = oend;
35453e202c1Schristos 	env->curname = oname;
35553e202c1Schristos 	env->stat = aml_stat_none;
35653e202c1Schristos }
35753e202c1Schristos 
35853e202c1Schristos static union aml_object *
aml_parse_defbuffer(struct aml_environ * env,int indent)35953e202c1Schristos aml_parse_defbuffer(struct aml_environ *env, int indent)
36053e202c1Schristos {
36153e202c1Schristos 	u_int8_t	*start;
36253e202c1Schristos 	u_int8_t	*end;
36353e202c1Schristos 	u_int8_t	*buffer;
36453e202c1Schristos 	u_int32_t	pkglength;
36553e202c1Schristos 	int	size1, size2, size;
36653e202c1Schristos 	union	aml_object *obj;
36753e202c1Schristos 
36853e202c1Schristos 	start = env->dp;
36953e202c1Schristos 	pkglength = aml_parse_pkglength(env);
37053e202c1Schristos 	end = start + pkglength;
37153e202c1Schristos 
37253e202c1Schristos 	AML_DEBUGPRINT("Buffer(");
37353e202c1Schristos 	obj = aml_eval_name(env, aml_parse_termobj(env, indent));
37453e202c1Schristos 	size1 = aml_objtonum(env, obj);
37553e202c1Schristos 	size2 = end - env->dp;
37653e202c1Schristos 	size = (size1 < size2) ? size1 : size2;
37753e202c1Schristos 	if (size1 > 0) {
37853e202c1Schristos 		buffer = memman_alloc_flexsize(aml_memman, size1);
37953e202c1Schristos 		if (buffer == NULL) {
38053e202c1Schristos 			AML_DEBUGPRINT("NO MEMORY\n");
38153e202c1Schristos 			env->stat = aml_stat_panic;
38253e202c1Schristos 			return (NULL);
38353e202c1Schristos 		}
38453e202c1Schristos 		bzero(buffer, size1);
38553e202c1Schristos 		bcopy(env->dp, buffer, size);
38653e202c1Schristos 	} else {
38753e202c1Schristos 		buffer = NULL;
38853e202c1Schristos 	}
38953e202c1Schristos 
39053e202c1Schristos 	obj = &env->tempobject;
39153e202c1Schristos 	obj->type = aml_t_buffer;
39253e202c1Schristos 	obj->buffer.size = size1;
39353e202c1Schristos 	obj->buffer.data = buffer;
39453e202c1Schristos 	AML_DEBUGPRINT(") ");
39553e202c1Schristos 	env->dp = end;
39653e202c1Schristos 
39753e202c1Schristos 	return (obj);
39853e202c1Schristos }
39953e202c1Schristos 
40053e202c1Schristos static struct aml_name *
aml_parse_concat_number(struct aml_environ * env,int num1,int indent)40153e202c1Schristos aml_parse_concat_number(struct aml_environ *env, int num1, int indent)
40253e202c1Schristos {
40353e202c1Schristos 	int	num2;
40453e202c1Schristos 	struct	aml_name *destname;
40553e202c1Schristos 	union	aml_object *obj;
40653e202c1Schristos 
40753e202c1Schristos 	num2 = aml_objtonum(env, aml_eval_name(env,
40853e202c1Schristos 		aml_parse_termobj(env, indent)));
40953e202c1Schristos 	AML_DEBUGPRINT(", ");
41053e202c1Schristos 	destname = aml_parse_termobj(env, indent);
41153e202c1Schristos 	AML_DEBUGPRINT(")");
41253e202c1Schristos 	obj = &env->tempobject;
41353e202c1Schristos 	obj->type = aml_t_buffer;
41453e202c1Schristos 	obj->buffer.size = 2;
41553e202c1Schristos 	obj->buffer.data = memman_alloc_flexsize(aml_memman, 2);
41653e202c1Schristos 	if (obj->buffer.data == NULL) {
41753e202c1Schristos 		env->stat = aml_stat_panic;
41853e202c1Schristos 		return (NULL);
41953e202c1Schristos 	}
42053e202c1Schristos 	obj->buffer.data[0] = num1 & 0xff;
42153e202c1Schristos 	obj->buffer.data[1] = num2 & 0xff;
42253e202c1Schristos 	aml_store_to_name(env, obj, destname);
42353e202c1Schristos 	return (&env->tempname);
42453e202c1Schristos }
42553e202c1Schristos 
42653e202c1Schristos static struct aml_name *
aml_parse_concat_buffer(struct aml_environ * env,union aml_object * obj,int indent)42753e202c1Schristos aml_parse_concat_buffer(struct aml_environ *env, union aml_object *obj,
42853e202c1Schristos     int indent)
42953e202c1Schristos {
43053e202c1Schristos 	union	aml_object *tmpobj, *tmpobj2, *resobj;
43153e202c1Schristos 	struct	aml_name *destname;
43253e202c1Schristos 
43353e202c1Schristos 	tmpobj = aml_eval_name(env, aml_parse_termobj(env, indent));
43453e202c1Schristos 	AML_DEBUGPRINT(", ");
43553e202c1Schristos 	if (tmpobj->type != aml_t_buffer) {
43653e202c1Schristos 		env->stat = aml_stat_panic;
43753e202c1Schristos 		return (NULL);
43853e202c1Schristos 	}
43953e202c1Schristos 	AML_COPY_OBJECT(tmpobj2, env, tmpobj, NULL);
44053e202c1Schristos 	destname = aml_parse_termobj(env, indent);
44153e202c1Schristos 	AML_DEBUGPRINT(")");
44253e202c1Schristos 	resobj = &env->tempobject;
44353e202c1Schristos 	env->tempname.property = resobj;
44453e202c1Schristos 	resobj->buffer.type = aml_t_buffer;
44553e202c1Schristos 	resobj->buffer.size = tmpobj2->buffer.size + obj->buffer.size;
44653e202c1Schristos 	if (resobj->buffer.size > 0) {
44753e202c1Schristos 		resobj->buffer.data = memman_alloc_flexsize(aml_memman,
44853e202c1Schristos 		    resobj->buffer.size);
44953e202c1Schristos 		if (resobj->buffer.data == NULL) {
45053e202c1Schristos 			env->stat = aml_stat_panic;
45153e202c1Schristos 			return (NULL);
45253e202c1Schristos 		}
45353e202c1Schristos 		bcopy(obj->buffer.data, resobj->buffer.data, obj->buffer.size);
45453e202c1Schristos 		bcopy(tmpobj2->buffer.data,
45553e202c1Schristos 		    resobj->buffer.data + obj->buffer.size,
45653e202c1Schristos 		    tmpobj2->buffer.size);
45753e202c1Schristos 	} else {
45853e202c1Schristos 		resobj->buffer.data = NULL;
45953e202c1Schristos 	}
46053e202c1Schristos 	aml_free_object(&tmpobj2);
46153e202c1Schristos 	aml_store_to_name(env, resobj, destname);
46253e202c1Schristos 	return (&env->tempname);
46353e202c1Schristos }
46453e202c1Schristos 
46553e202c1Schristos static struct aml_name *
aml_parse_concat_string(struct aml_environ * env,union aml_object * obj,int indent)46653e202c1Schristos aml_parse_concat_string(struct aml_environ *env, union aml_object *obj,
46753e202c1Schristos     int indent)
46853e202c1Schristos {
46953e202c1Schristos 	int	len;
47053e202c1Schristos 	union	aml_object *tmpobj, *tmpobj2, *resobj;
47153e202c1Schristos 	struct	aml_name *destname;
47253e202c1Schristos 
47353e202c1Schristos 	tmpobj = aml_eval_name(env, aml_parse_termobj(env, indent));
47453e202c1Schristos 	AML_DEBUGPRINT(", ");
47553e202c1Schristos 	if (tmpobj->type != aml_t_string) {
47653e202c1Schristos 		env->stat = aml_stat_panic;
47753e202c1Schristos 		return (NULL);
47853e202c1Schristos 	}
47953e202c1Schristos 	AML_COPY_OBJECT(tmpobj2, env, tmpobj, NULL);
48053e202c1Schristos 	destname = aml_parse_termobj(env, indent);
48153e202c1Schristos 	AML_DEBUGPRINT(")");
48253e202c1Schristos 	resobj = &env->tempobject;
48353e202c1Schristos 	env->tempname.property = resobj;
48453e202c1Schristos 	resobj->type = aml_t_buffer;
48553e202c1Schristos 	resobj->str.needfree = 1;
48653e202c1Schristos 	len = strlen((const char *)obj->str.string) +
48753e202c1Schristos 	    strlen((const char *)tmpobj2->str.string) + 1;
48853e202c1Schristos 	if (len > 0) {
48953e202c1Schristos 		resobj->str.string = memman_alloc_flexsize(aml_memman, len);
49053e202c1Schristos 		if (resobj->str.string == NULL) {
49153e202c1Schristos 			env->stat = aml_stat_panic;
49253e202c1Schristos 			return (NULL);
49353e202c1Schristos 		}
49453e202c1Schristos 		strlcpy((char *)resobj->str.string, (const char *)obj->str.string, len);
49553e202c1Schristos 		strlcat((char *)resobj->str.string, (const char *)tmpobj->str.string, len);
49653e202c1Schristos 	} else {
49753e202c1Schristos 		resobj->str.string = NULL;
49853e202c1Schristos 	}
49953e202c1Schristos 	aml_free_object(&tmpobj2);
50053e202c1Schristos 	aml_store_to_name(env, resobj, destname);
50153e202c1Schristos 	return (&env->tempname);
50253e202c1Schristos }
50353e202c1Schristos 
50453e202c1Schristos static struct aml_name *
aml_parse_concatop(struct aml_environ * env,int indent)50553e202c1Schristos aml_parse_concatop(struct aml_environ *env, int indent)
50653e202c1Schristos {
50753e202c1Schristos 	union	aml_object *obj, *tmpobj;
50853e202c1Schristos 	struct	aml_name *aname;
50953e202c1Schristos 
51053e202c1Schristos 	AML_DEBUGPRINT("Concat(");
51153e202c1Schristos 	obj = aml_eval_name(env, aml_parse_termobj(env, indent));
51253e202c1Schristos 	AML_DEBUGPRINT(", ");
51353e202c1Schristos 	switch (obj->type) {
51453e202c1Schristos 	case aml_t_num:
51553e202c1Schristos 		aname = aml_parse_concat_number(env, aml_objtonum(env, obj), indent);
51653e202c1Schristos 		break;
51753e202c1Schristos 
51853e202c1Schristos 	case aml_t_buffer:
51953e202c1Schristos 		/* obj may be temporal object */
52053e202c1Schristos 		AML_COPY_OBJECT(tmpobj, env, obj, NULL);
52153e202c1Schristos 		aname = aml_parse_concat_buffer(env, obj, indent);
52253e202c1Schristos 		aml_free_object(&tmpobj);
52353e202c1Schristos 		break;
52453e202c1Schristos 
52553e202c1Schristos 	case aml_t_string:
52653e202c1Schristos 		/* obj may be temporal object */
52753e202c1Schristos 		AML_COPY_OBJECT(tmpobj, env, obj, NULL);
52853e202c1Schristos 		aname = aml_parse_concat_string(env, obj, indent);
52953e202c1Schristos 		aml_free_object(&tmpobj);
53053e202c1Schristos 		break;
53153e202c1Schristos 
53253e202c1Schristos 	default:
53353e202c1Schristos 		env->stat = aml_stat_panic;
53453e202c1Schristos 		aname = NULL;
53553e202c1Schristos 		break;
53653e202c1Schristos 	}
53753e202c1Schristos 
53853e202c1Schristos 	AML_DEBUGPRINT("\n");
53953e202c1Schristos 	return (aname);
54053e202c1Schristos }
54153e202c1Schristos 
54253e202c1Schristos static union aml_object *
aml_parse_defpackage(struct aml_environ * env,int indent)54353e202c1Schristos aml_parse_defpackage(struct aml_environ *env, int indent)
54453e202c1Schristos {
54553e202c1Schristos 	u_int8_t	numelements;
54653e202c1Schristos 	u_int8_t	*start;
54753e202c1Schristos 	u_int32_t	pkglength;
54853e202c1Schristos 	int		i;
54953e202c1Schristos 	struct	aml_environ *copy;
55053e202c1Schristos 	struct	aml_name *tmpname;
55153e202c1Schristos 	union	aml_object *obj, **objects;
55253e202c1Schristos 
55353e202c1Schristos 	start = env->dp;
55453e202c1Schristos 	pkglength = aml_parse_pkglength(env);
55553e202c1Schristos 	numelements = aml_parse_bytedata(env);
55653e202c1Schristos 	copy = memman_alloc(aml_memman, memid_aml_environ);
55753e202c1Schristos 	if (copy == NULL) {
55853e202c1Schristos 		env->stat = aml_stat_panic;
55953e202c1Schristos 		return (NULL);
56053e202c1Schristos 	}
56153e202c1Schristos 	if (numelements > 0) {
56253e202c1Schristos 		objects = memman_alloc_flexsize(aml_memman,
56353e202c1Schristos 		    numelements * sizeof(union aml_object *));
56453e202c1Schristos 		if (objects == NULL) {
56553e202c1Schristos 			env->stat = aml_stat_panic;
56653e202c1Schristos 			return (NULL);
56753e202c1Schristos 		} else {
56853e202c1Schristos 			bzero(objects, numelements * sizeof(union aml_object *));
56953e202c1Schristos 		}
57053e202c1Schristos 	} else {
57153e202c1Schristos 		objects = NULL;
57253e202c1Schristos 	}
57353e202c1Schristos 
57453e202c1Schristos 	*copy = *env;
57553e202c1Schristos 	env->dp = copy->end = start + pkglength;
57653e202c1Schristos 	AML_DEBUGPRINT("Package() {\n");
57753e202c1Schristos 	i = 0;
57853e202c1Schristos 	while ((copy->dp < copy->end) && (i < numelements)) {
57953e202c1Schristos 		aml_print_indent(indent + 1);
58053e202c1Schristos 		tmpname = aml_parse_termobj(copy, indent + 1);
58153e202c1Schristos 
58253e202c1Schristos 		if (tmpname != NULL) {
58353e202c1Schristos 			objects[i] = aml_copy_object(copy, tmpname->property);
58453e202c1Schristos 		}
58553e202c1Schristos 		AML_DEBUGPRINT(",\n");
58653e202c1Schristos 		i++;
58753e202c1Schristos 	}
58853e202c1Schristos 	aml_free_objectcontent(&copy->tempobject);
58953e202c1Schristos 
59053e202c1Schristos 	aml_print_indent(indent);
59153e202c1Schristos 	AML_DEBUGPRINT("}");
59253e202c1Schristos 	obj = &env->tempobject;
59353e202c1Schristos 	obj->type = aml_t_package;
59453e202c1Schristos 	obj->package.elements = numelements;
59553e202c1Schristos 	obj->package.objects = objects;
59653e202c1Schristos 
59753e202c1Schristos 	memman_free(aml_memman, memid_aml_environ, copy);
59853e202c1Schristos 	return (obj);
59953e202c1Schristos }
60053e202c1Schristos 
60153e202c1Schristos static void
aml_parse_defmethod(struct aml_environ * env,int indent)60253e202c1Schristos aml_parse_defmethod(struct aml_environ *env, int indent)
60353e202c1Schristos {
60453e202c1Schristos 	u_int8_t	flags;
60553e202c1Schristos 	u_int8_t	*start;
60653e202c1Schristos 	u_int32_t	pkglength;
60753e202c1Schristos 	char	*name;
60853e202c1Schristos 	struct	aml_environ *copy;
60953e202c1Schristos 	struct	aml_method *meth;
61053e202c1Schristos 	struct	aml_name *aname;
61153e202c1Schristos 	union	aml_object *aobj;
61253e202c1Schristos 
61353e202c1Schristos 	start = env->dp;
61453e202c1Schristos 	pkglength = aml_parse_pkglength(env);
61553e202c1Schristos 	copy = memman_alloc(aml_memman, memid_aml_environ);
61653e202c1Schristos 	if (copy == NULL) {
61753e202c1Schristos 		env->stat = aml_stat_panic;
61853e202c1Schristos 		return;
61953e202c1Schristos 	}
62053e202c1Schristos 	AML_DEBUGPRINT("Method(");
62153e202c1Schristos 	name = (char *)aml_parse_namestring(env);
62253e202c1Schristos 	aml_print_namestring((unsigned char *)name);
62353e202c1Schristos 	AML_CREATE_NAME(aname, env, (unsigned char *)name,);
62453e202c1Schristos 	if (aname->property != NULL) {
62553e202c1Schristos 		env->stat = aml_stat_panic;
62653e202c1Schristos 		AML_DEBUGPRINT("Already Defined \n");
62753e202c1Schristos 		goto out;
62853e202c1Schristos 	}
62953e202c1Schristos 	AML_ALLOC_OBJECT(aobj, env, aml_t_method,);
63053e202c1Schristos 	meth = &aobj->meth;
63153e202c1Schristos 	aname->property = aobj;
63253e202c1Schristos 	flags = *env->dp++;
63353e202c1Schristos 
63453e202c1Schristos 	if (flags) {
63553e202c1Schristos 		AML_DEBUGPRINT(", %d", flags);
63653e202c1Schristos 	}
63753e202c1Schristos 	AML_DEBUGPRINT(") {\n");
63853e202c1Schristos 	*copy = *env;
63953e202c1Schristos 	meth->argnum = flags;
64053e202c1Schristos 	meth->from = env->dp;
64153e202c1Schristos 	meth->to = env->dp = copy->end = start + pkglength;
64253e202c1Schristos 	aml_print_indent(indent);
64353e202c1Schristos 	AML_DEBUGPRINT("}");
64453e202c1Schristos out:
64553e202c1Schristos 	memman_free(aml_memman, memid_aml_environ, copy);
64653e202c1Schristos }
64753e202c1Schristos 
64853e202c1Schristos static void
aml_parse_defopregion(struct aml_environ * env,int indent)64953e202c1Schristos aml_parse_defopregion(struct aml_environ *env, int indent)
65053e202c1Schristos {
65153e202c1Schristos 	u_int8_t	*name;
65253e202c1Schristos 	struct	aml_name *aname;
65353e202c1Schristos 	struct	aml_opregion *opregion;
65453e202c1Schristos 	union	aml_object *obj;
65553e202c1Schristos 	const char	*regions[] = {
65653e202c1Schristos 		"SystemMemory",
65753e202c1Schristos 		"SystemIO",
65853e202c1Schristos 		"PCI_Config",
65953e202c1Schristos 		"EmbeddedControl",
66053e202c1Schristos 		"SMBus",
66153e202c1Schristos 	};
66253e202c1Schristos 
66353e202c1Schristos 	AML_DEBUGPRINT("OperationRegion(");
66453e202c1Schristos 	/* Name */
66553e202c1Schristos 	name = aml_parse_namestring(env);
66653e202c1Schristos 	aml_print_namestring(name);
66753e202c1Schristos 	AML_CREATE_NAME(aname, env, name,);
66853e202c1Schristos 	if (aname->property != NULL) {
66953e202c1Schristos 		env->stat = aml_stat_panic;
67053e202c1Schristos 		AML_DEBUGPRINT("Already Defined \n");
67153e202c1Schristos 		return;
67253e202c1Schristos 	}
67353e202c1Schristos 	AML_ALLOC_OBJECT(aname->property, env, aml_t_opregion,);
67453e202c1Schristos 	opregion = &aname->property->opregion;
67553e202c1Schristos 	opregion->space = *env->dp;
67653e202c1Schristos 	AML_DEBUGPRINT(", %s, ", regions[*env->dp]);	/* Space */
67753e202c1Schristos 	env->dp++;
67853e202c1Schristos 	obj = aml_eval_name(env, aml_parse_termobj(env, indent));	/* Offset */
67953e202c1Schristos 	opregion->offset = aml_objtonum(env, obj);
68053e202c1Schristos 	AML_DEBUGPRINT(", ");
68153e202c1Schristos 	obj = aml_eval_name(env, aml_parse_termobj(env, indent));	/* Length */
68253e202c1Schristos 	opregion->length = aml_objtonum(env, obj);
68353e202c1Schristos 	AML_DEBUGPRINT(")");
68453e202c1Schristos }
68553e202c1Schristos 
68653e202c1Schristos static const char	*accessnames[] = {
68753e202c1Schristos 	"AnyAcc",
68853e202c1Schristos 	"ByteAcc",
68953e202c1Schristos 	"WordAcc",
69053e202c1Schristos 	"DWordAcc",
69153e202c1Schristos 	"BlockAcc",
69253e202c1Schristos 	"SMBSendRecvAcc",
69353e202c1Schristos 	"SMBQuickAcc"
69453e202c1Schristos };
69553e202c1Schristos 
69653e202c1Schristos static int
aml_parse_field(struct aml_environ * env,struct aml_field * template)69753e202c1Schristos aml_parse_field(struct aml_environ *env, struct aml_field *template)
69853e202c1Schristos {
69953e202c1Schristos 	u_int8_t	*name;
70053e202c1Schristos 	u_int8_t	acc, attribute;
70153e202c1Schristos 	u_int32_t	width;
70253e202c1Schristos 	struct	aml_name *aname;
70353e202c1Schristos 	struct	aml_field *prop;
70453e202c1Schristos 
70553e202c1Schristos 	switch (*env->dp) {
70653e202c1Schristos 	case '\\':
70753e202c1Schristos 	case '^':
70853e202c1Schristos 	case 'A'...'Z':
70953e202c1Schristos 	case '_':
71053e202c1Schristos 	case '.':
71153e202c1Schristos 	case '/':
71253e202c1Schristos 		name = aml_parse_namestring(env);
71353e202c1Schristos 		width = aml_parse_pkglength(env);
71453e202c1Schristos 		template->bitlen = width;
71553e202c1Schristos 		aml_print_namestring(name);
71653e202c1Schristos 		AML_CREATE_NAME(aname, env, name, 0);
717fb817dabSandvar 		/* Alignment */
71853e202c1Schristos 		if (width == 16) {
71953e202c1Schristos 			template->bitoffset += 15;
72053e202c1Schristos 			template->bitoffset &= (~15);
72153e202c1Schristos 		}
72253e202c1Schristos 		if (width == 32) {
72353e202c1Schristos 			template->bitoffset += 31;
72453e202c1Schristos 			template->bitoffset &= (~31);
72553e202c1Schristos 		} else if ((width & 7) == 0) {
72653e202c1Schristos 			template->bitoffset += 7;
72753e202c1Schristos 			template->bitoffset &= (~7);
72853e202c1Schristos 		} else if ((width > 32) && (width & 7) != 0) {
72953e202c1Schristos 			AML_DEBUGPRINT("??? Can I treat it?\n");
73053e202c1Schristos 		}
73153e202c1Schristos 		if (aname->property != NULL) {
73253e202c1Schristos 			env->stat = aml_stat_panic;
73353e202c1Schristos 			AML_DEBUGPRINT("Already Defined \n");
73453e202c1Schristos 			return (0);
73553e202c1Schristos 		}
73653e202c1Schristos 		AML_ALLOC_OBJECT(aname->property, env, aml_t_field, 0);
73753e202c1Schristos 		prop = &aname->property->field;
73853e202c1Schristos 		*prop = *template;
73953e202c1Schristos 		template->bitoffset += width;
74053e202c1Schristos 		AML_DEBUGPRINT(",\t%d", width);
74153e202c1Schristos 		break;
74253e202c1Schristos 	case 0x00:
74353e202c1Schristos 		env->dp++;
74453e202c1Schristos 		width = aml_parse_pkglength(env);
74553e202c1Schristos 		template->bitoffset += width;
74653e202c1Schristos 		AML_DEBUGPRINT("Offset(0x%x)", template->bitoffset);
74753e202c1Schristos 		break;
74853e202c1Schristos 	case 0x01:
74953e202c1Schristos 		acc = env->dp[1];
75053e202c1Schristos 		attribute = env->dp[2];
75153e202c1Schristos 		env->dp += 3;
75253e202c1Schristos 		AML_DEBUGPRINT("AccessAs(%s, %d)", accessnames[acc], attribute);
75353e202c1Schristos 		template->bitoffset = attribute;
75453e202c1Schristos 		template->flags = (template->flags | 0xf0) | acc;
75553e202c1Schristos 		break;
75653e202c1Schristos 	}
75753e202c1Schristos 	return (template->bitoffset);
75853e202c1Schristos }
75953e202c1Schristos 
76053e202c1Schristos static void
aml_parse_fieldlist(struct aml_environ * env,struct aml_field * template,int indent)76153e202c1Schristos aml_parse_fieldlist(struct aml_environ *env, struct aml_field *template,
76253e202c1Schristos     int indent)
76353e202c1Schristos {
76453e202c1Schristos 
76553e202c1Schristos 	while (env->dp < env->end) {
76653e202c1Schristos 		aml_print_indent(indent);
7670a77b69aSchristos 		(void)aml_parse_field(env, template);
76853e202c1Schristos 		if (env->dp < env->end) {
76953e202c1Schristos 			AML_DEBUGPRINT(",\n");
77053e202c1Schristos 		} else {
77153e202c1Schristos 			AML_DEBUGPRINT("\n");
77253e202c1Schristos 		}
77353e202c1Schristos 	}
77453e202c1Schristos }
77553e202c1Schristos 
77653e202c1Schristos static void
aml_parse_deffield(struct aml_environ * env,int indent)77753e202c1Schristos aml_parse_deffield(struct aml_environ *env, int indent)
77853e202c1Schristos {
77953e202c1Schristos 	u_int8_t	flags;
78053e202c1Schristos 	u_int8_t	*start, *name;
78153e202c1Schristos 	u_int32_t	pkglength;
78253e202c1Schristos 	struct	aml_environ *copy;
78353e202c1Schristos 	struct	aml_field fieldtemplate;
78453e202c1Schristos 	static	const char *lockrules[] = {"NoLock", "Lock"};
78553e202c1Schristos 	static	const char *updaterules[] = {"Preserve", "WriteAsOnes",
78653e202c1Schristos 					     "WriteAsZeros", "*Error*"};
78753e202c1Schristos 
78853e202c1Schristos 	start = env->dp;
78953e202c1Schristos 	pkglength = aml_parse_pkglength(env);
79053e202c1Schristos 	copy = memman_alloc(aml_memman, memid_aml_environ);
79153e202c1Schristos 	if (copy == NULL) {
79253e202c1Schristos 		env->stat = aml_stat_panic;
79353e202c1Schristos 		return;
79453e202c1Schristos 	}
79553e202c1Schristos 	AML_DEBUGPRINT("Field(");
79653e202c1Schristos 	aml_print_namestring(name = aml_parse_namestring(env));
79753e202c1Schristos 	fieldtemplate.type = aml_t_field;
79853e202c1Schristos 	flags = aml_parse_bytedata(env);
7992c77b084Smrg 	fieldtemplate.flags = flags;
80053e202c1Schristos 
80153e202c1Schristos 	*copy = *env;
80253e202c1Schristos 	env->dp = copy->end = start + pkglength;
80353e202c1Schristos 	fieldtemplate.bitoffset = 0;
80453e202c1Schristos 	fieldtemplate.bitlen = 0;
80553e202c1Schristos 	fieldtemplate.f.ftype = f_t_field;
80653e202c1Schristos 	fieldtemplate.f.fld.regname = name;
80753e202c1Schristos 	AML_DEBUGPRINT(", %s, %s, %s) {\n",
80853e202c1Schristos 	    accessnames[flags & 0xf],
80953e202c1Schristos 	    lockrules[(flags >> 4) & 1],
81053e202c1Schristos 	    updaterules[(flags >> 5) & 3]);
81153e202c1Schristos 	aml_parse_fieldlist(copy, &fieldtemplate, indent + 1);
81253e202c1Schristos 	aml_print_indent(indent);
81353e202c1Schristos 	AML_DEBUGPRINT("}");
81453e202c1Schristos 	aml_free_objectcontent(&copy->tempobject);
81553e202c1Schristos 
81653e202c1Schristos 	AML_SYSASSERT(copy->dp == copy->end);
81753e202c1Schristos 	memman_free(aml_memman, memid_aml_environ, copy);
81853e202c1Schristos }
81953e202c1Schristos 
82053e202c1Schristos static void
aml_parse_defindexfield(struct aml_environ * env,int indent)82153e202c1Schristos aml_parse_defindexfield(struct aml_environ *env, int indent)
82253e202c1Schristos {
82353e202c1Schristos 	u_int8_t	flags;
82453e202c1Schristos 	u_int8_t	*start, *iname, *dname;
82553e202c1Schristos 	u_int32_t	pkglength;
82653e202c1Schristos 	struct	aml_environ *copy;
82753e202c1Schristos 	struct	aml_field template;
82853e202c1Schristos 	static	const char *lockrules[] = {"NoLock", "Lock"};
82953e202c1Schristos 	static	const char *updaterules[] = {"Preserve", "WriteAsOnes",
83053e202c1Schristos 					     "WriteAsZeros", "*Error*"};
83153e202c1Schristos 
83253e202c1Schristos 	start = env->dp;
83353e202c1Schristos 	pkglength = aml_parse_pkglength(env);
83453e202c1Schristos 	copy = memman_alloc(aml_memman, memid_aml_environ);
83553e202c1Schristos 	if (copy == NULL) {
83653e202c1Schristos 		env->stat = aml_stat_panic;
83753e202c1Schristos 		return;
83853e202c1Schristos 	}
83953e202c1Schristos 	AML_DEBUGPRINT("IndexField(");
84053e202c1Schristos 	aml_print_namestring(iname = aml_parse_namestring(env));	/* Name1 */
84153e202c1Schristos 	AML_DEBUGPRINT(", ");
84253e202c1Schristos 	aml_print_namestring(dname = aml_parse_namestring(env));	/* Name2 */
84353e202c1Schristos 	template.type = aml_t_field;
84453e202c1Schristos 	template.flags = flags = aml_parse_bytedata(env);
84553e202c1Schristos 	template.bitoffset = 0;
84653e202c1Schristos 	template.bitlen = 0;
84753e202c1Schristos 	template.f.ftype = f_t_index;
84853e202c1Schristos 	template.f.ifld.indexname = iname;
84953e202c1Schristos 	template.f.ifld.dataname = dname;
85053e202c1Schristos 	AML_DEBUGPRINT(", %s, %s, %s) {\n",
85153e202c1Schristos 	    accessnames[flags & 0xf],
85253e202c1Schristos 	    lockrules[(flags >> 4) & 1],
85353e202c1Schristos 	    updaterules[(flags >> 5) & 3]);
85453e202c1Schristos 	*copy = *env;
85553e202c1Schristos 	env->dp = copy->end = start + pkglength;
85653e202c1Schristos 	aml_parse_fieldlist(copy, &template, indent + 1);
85753e202c1Schristos 	aml_print_indent(indent);
85853e202c1Schristos 	AML_DEBUGPRINT("}");
85953e202c1Schristos 	aml_free_objectcontent(&copy->tempobject);
86053e202c1Schristos 
86153e202c1Schristos 	AML_SYSASSERT(copy->dp == copy->end);
86253e202c1Schristos 	memman_free(aml_memman, memid_aml_environ, copy);
86353e202c1Schristos }
86453e202c1Schristos 
86553e202c1Schristos static void
aml_parse_defbankfield(struct aml_environ * env,int indent)86653e202c1Schristos aml_parse_defbankfield(struct aml_environ *env, int indent)
86753e202c1Schristos {
86853e202c1Schristos 	u_int8_t	flags;
86953e202c1Schristos 	u_int8_t	*start, *rname, *bname;
87053e202c1Schristos 	u_int32_t	pkglength, bankvalue;
87153e202c1Schristos 	struct	aml_environ *copy;
87253e202c1Schristos 	struct	aml_field template;
87353e202c1Schristos 	union	aml_object *obj;
87453e202c1Schristos 	static	const char *lockrules[] = {"NoLock", "Lock"};
87553e202c1Schristos 	static	const char *updaterules[] = {"Preserve", "WriteAsOnes",
87653e202c1Schristos 					     "WriteAsZeros", "*Error*"};
87753e202c1Schristos 
87853e202c1Schristos 	start = env->dp;
87953e202c1Schristos 	pkglength = aml_parse_pkglength(env);
88053e202c1Schristos 	copy = memman_alloc(aml_memman, memid_aml_environ);
88153e202c1Schristos 	if (copy == NULL) {
88253e202c1Schristos 		env->stat = aml_stat_panic;
88353e202c1Schristos 		return;
88453e202c1Schristos 	}
88553e202c1Schristos 	AML_DEBUGPRINT("BankField(");
88653e202c1Schristos 	aml_print_namestring(rname = aml_parse_namestring(env));	/* Name1 */
88753e202c1Schristos 	AML_DEBUGPRINT(", ");
88853e202c1Schristos 	aml_print_namestring(bname = aml_parse_namestring(env));	/* Name2 */
88953e202c1Schristos 	AML_DEBUGPRINT(", ");
89053e202c1Schristos 	obj = aml_eval_name(env, aml_parse_termobj(env, indent));	/* BankValue */
89153e202c1Schristos 	bankvalue = aml_objtonum(env, obj);
89253e202c1Schristos 	template.type = aml_t_field;
89353e202c1Schristos 	template.flags = flags = aml_parse_bytedata(env);
89453e202c1Schristos 	template.bitoffset = 0;
89553e202c1Schristos 	template.bitlen = 0;
89653e202c1Schristos 	template.f.ftype = f_t_bank;
89753e202c1Schristos 	template.f.bfld.regname = rname;
89853e202c1Schristos 	template.f.bfld.bankname = bname;
89953e202c1Schristos 	template.f.bfld.bankvalue = bankvalue;
90053e202c1Schristos 	*copy = *env;
90153e202c1Schristos 	env->dp = copy->end = start + pkglength;
90253e202c1Schristos 	AML_DEBUGPRINT(", %s, %s, %s) {\n",
90353e202c1Schristos 	    accessnames[flags & 0xf],
90453e202c1Schristos 	    lockrules[(flags >> 4) & 1],
90553e202c1Schristos 	    updaterules[(flags >> 5) & 3]);
90653e202c1Schristos 	aml_parse_fieldlist(copy, &template, indent + 1);
90753e202c1Schristos 	aml_print_indent(indent);
90853e202c1Schristos 	AML_DEBUGPRINT("}");
90953e202c1Schristos 
91053e202c1Schristos 	aml_free_objectcontent(&copy->tempobject);
91153e202c1Schristos 	AML_SYSASSERT(copy->dp == copy->end);
91253e202c1Schristos 	memman_free(aml_memman, memid_aml_environ, copy);
91353e202c1Schristos }
91453e202c1Schristos 
91553e202c1Schristos static void
aml_parse_defdevice(struct aml_environ * env,int indent)91653e202c1Schristos aml_parse_defdevice(struct aml_environ *env, int indent)
91753e202c1Schristos {
91853e202c1Schristos 	u_int8_t	*start;
91953e202c1Schristos 	u_int8_t	*name;
92053e202c1Schristos 	u_int32_t	pkglength;
92153e202c1Schristos 	struct	aml_environ *copy;
92253e202c1Schristos 
92353e202c1Schristos 	start = env->dp;
92453e202c1Schristos 	pkglength = aml_parse_pkglength(env);
92553e202c1Schristos 	copy = memman_alloc(aml_memman, memid_aml_environ);
92653e202c1Schristos 	if (copy == NULL) {
92753e202c1Schristos 		env->stat = aml_stat_panic;
92853e202c1Schristos 		return;
92953e202c1Schristos 	}
93053e202c1Schristos 	AML_DEBUGPRINT("Device(");
93153e202c1Schristos 	name = aml_parse_namestring(env);
93253e202c1Schristos 	aml_print_namestring(name);
93353e202c1Schristos 	AML_DEBUGPRINT(") {\n");
93453e202c1Schristos 	*copy = *env;
93553e202c1Schristos 	AML_CREATE_NAME(copy->curname, env, name,);
93653e202c1Schristos 	if (copy->curname->property != NULL) {
93753e202c1Schristos 		env->stat = aml_stat_panic;
93853e202c1Schristos 		AML_DEBUGPRINT("Already Defined \n");
93953e202c1Schristos 		goto out;
94053e202c1Schristos 	}
94153e202c1Schristos 	AML_ALLOC_OBJECT(copy->curname->property, env, aml_t_device,);
94253e202c1Schristos 	env->dp = copy->end = start + pkglength;
94353e202c1Schristos 	aml_parse_objectlist(copy, indent + 1);
94453e202c1Schristos 	aml_print_indent(indent);
94553e202c1Schristos 	AML_DEBUGPRINT("}");
94653e202c1Schristos 	aml_free_objectcontent(&copy->tempobject);
94753e202c1Schristos 
94853e202c1Schristos 	AML_SYSASSERT(copy->dp == copy->end);
94953e202c1Schristos out:
95053e202c1Schristos 	memman_free(aml_memman, memid_aml_environ, copy);
95153e202c1Schristos }
95253e202c1Schristos 
95353e202c1Schristos static void
aml_parse_defprocessor(struct aml_environ * env,int indent)95453e202c1Schristos aml_parse_defprocessor(struct aml_environ *env, int indent)
95553e202c1Schristos {
95653e202c1Schristos 	u_int8_t	*start;
95753e202c1Schristos 	u_int8_t	*name;
95853e202c1Schristos 	u_int32_t	pkglength;
95953e202c1Schristos 	struct	aml_environ *copy;
96053e202c1Schristos 	struct	aml_processor *proc;
96153e202c1Schristos 	union	aml_object *obj;
96253e202c1Schristos 
96353e202c1Schristos 	start = env->dp;
96453e202c1Schristos 	pkglength = aml_parse_pkglength(env);
96553e202c1Schristos 	copy = memman_alloc(aml_memman, memid_aml_environ);
96653e202c1Schristos 	if (copy == NULL) {
96753e202c1Schristos 		env->stat = aml_stat_panic;
96853e202c1Schristos 		return;
96953e202c1Schristos 	}
97053e202c1Schristos 	AML_ALLOC_OBJECT(obj, env, aml_t_processor,);
97153e202c1Schristos 	proc = &obj->proc;
97253e202c1Schristos 	AML_DEBUGPRINT("Processor(");
97353e202c1Schristos 	name = aml_parse_namestring(env);
97453e202c1Schristos 	aml_print_namestring(name);
97553e202c1Schristos 	proc->id = aml_parse_bytedata(env);
97653e202c1Schristos 	proc->addr = aml_parse_dworddata(env);
97753e202c1Schristos 	proc->len = aml_parse_bytedata(env);
97853e202c1Schristos 	AML_DEBUGPRINT(", %d, 0x%x, 0x%x) {\n", proc->id, proc->addr, proc->len);
97953e202c1Schristos 	*copy = *env;
98053e202c1Schristos 	AML_CREATE_NAME(copy->curname, env, name,);
98153e202c1Schristos 	if (copy->curname->property != NULL) {
98253e202c1Schristos 		env->stat = aml_stat_panic;
98353e202c1Schristos 		AML_DEBUGPRINT("Already Defined \n");
98453e202c1Schristos 		goto out;
98553e202c1Schristos 	}
98653e202c1Schristos 	copy->curname->property = obj;
98753e202c1Schristos 	env->dp = copy->end = start + pkglength;
98853e202c1Schristos 	aml_parse_objectlist(copy, indent + 1);
98953e202c1Schristos 	aml_print_indent(indent);
99053e202c1Schristos 	AML_DEBUGPRINT("}");
99153e202c1Schristos 	aml_free_objectcontent(&copy->tempobject);
99253e202c1Schristos 
99353e202c1Schristos 	AML_SYSASSERT(copy->dp == copy->end);
99453e202c1Schristos out:
99553e202c1Schristos 	memman_free(aml_memman, memid_aml_environ, copy);
99653e202c1Schristos }
99753e202c1Schristos 
99853e202c1Schristos static void
aml_parse_defpowerres(struct aml_environ * env,int indent)99953e202c1Schristos aml_parse_defpowerres(struct aml_environ *env, int indent)
100053e202c1Schristos {
100153e202c1Schristos 	u_int8_t	*start;
100253e202c1Schristos 	u_int8_t	*name;
100353e202c1Schristos 	u_int32_t	pkglength;
100453e202c1Schristos 	struct	aml_environ *copy;
100553e202c1Schristos 	struct	aml_powerres *pres;
100653e202c1Schristos 	union	aml_object *obj;
100753e202c1Schristos 
100853e202c1Schristos 	start = env->dp;
100953e202c1Schristos 	pkglength = aml_parse_pkglength(env);
101053e202c1Schristos 	copy = memman_alloc(aml_memman, memid_aml_environ);
101153e202c1Schristos 	if (copy == NULL) {
101253e202c1Schristos 		env->stat = aml_stat_panic;
101353e202c1Schristos 		return;
101453e202c1Schristos 	}
101553e202c1Schristos 	AML_DEBUGPRINT("PowerResource(");
101653e202c1Schristos 	AML_ALLOC_OBJECT(obj, env, aml_t_powerres,);
101753e202c1Schristos 	name = aml_parse_namestring(env);
101853e202c1Schristos 	aml_print_namestring(name);
101953e202c1Schristos 	pres = &obj->pres;
102053e202c1Schristos 	pres->level = aml_parse_bytedata(env);
102153e202c1Schristos 	pres->order = aml_parse_worddata(env);
102253e202c1Schristos 	AML_DEBUGPRINT(", %d, %d) {\n", pres->level, pres->order);
102353e202c1Schristos 	*copy = *env;
102453e202c1Schristos 	AML_CREATE_NAME(copy->curname, env, name,);
102553e202c1Schristos 	if (copy->curname->property != NULL) {
102653e202c1Schristos 		env->stat = aml_stat_panic;
102753e202c1Schristos 		AML_DEBUGPRINT("Already Defined \n");
102853e202c1Schristos 		goto out;
102953e202c1Schristos 	}
103053e202c1Schristos 	copy->curname->property = obj;
103153e202c1Schristos 	env->dp = copy->end = start + pkglength;
103253e202c1Schristos 
103353e202c1Schristos 	aml_parse_objectlist(copy, indent + 1);
103453e202c1Schristos 	aml_print_indent(indent);
103553e202c1Schristos 	AML_DEBUGPRINT("}");
103653e202c1Schristos 	aml_free_objectcontent(&copy->tempobject);
103753e202c1Schristos 
103853e202c1Schristos 	AML_SYSASSERT(copy->dp == copy->end);
103953e202c1Schristos out:
104053e202c1Schristos 	memman_free(aml_memman, memid_aml_environ, copy);
104153e202c1Schristos }
104253e202c1Schristos 
104353e202c1Schristos static void
aml_parse_defthermalzone(struct aml_environ * env,int indent)104453e202c1Schristos aml_parse_defthermalzone(struct aml_environ *env, int indent)
104553e202c1Schristos {
104653e202c1Schristos 	u_int8_t	*start;
104753e202c1Schristos 	u_int8_t	*name;
104853e202c1Schristos 	u_int32_t	pkglength;
104953e202c1Schristos 	struct	aml_environ *copy;
105053e202c1Schristos 
105153e202c1Schristos 	start = env->dp;
105253e202c1Schristos 	pkglength = aml_parse_pkglength(env);
105353e202c1Schristos 	copy = memman_alloc(aml_memman, memid_aml_environ);
105453e202c1Schristos 	if (copy == NULL) {
105553e202c1Schristos 		env->stat = aml_stat_panic;
105653e202c1Schristos 		return;
105753e202c1Schristos 	}
105853e202c1Schristos 	AML_DEBUGPRINT("ThermalZone(");
105953e202c1Schristos 	name = aml_parse_namestring(env);
106053e202c1Schristos 	aml_print_namestring(name);
106153e202c1Schristos 	AML_DEBUGPRINT(") {\n");
106253e202c1Schristos 	*copy = *env;
106353e202c1Schristos 	AML_CREATE_NAME(copy->curname, env, name,);
106453e202c1Schristos 	if (copy->curname->property != NULL) {
106553e202c1Schristos 		env->stat = aml_stat_panic;
106653e202c1Schristos 		AML_DEBUGPRINT("Already Defined \n");
106753e202c1Schristos 		goto out;
106853e202c1Schristos 	}
106953e202c1Schristos 	AML_ALLOC_OBJECT(copy->curname->property, env, aml_t_therm,);
107053e202c1Schristos 	env->dp = copy->end = start + pkglength;
107153e202c1Schristos 	aml_parse_objectlist(copy, indent + 1);
107253e202c1Schristos 	aml_print_indent(indent);
107353e202c1Schristos 	AML_DEBUGPRINT("}");
107453e202c1Schristos 	aml_free_objectcontent(&copy->tempobject);
107553e202c1Schristos 	AML_SYSASSERT(copy->dp == copy->end);
107653e202c1Schristos out:
107753e202c1Schristos 	memman_free(aml_memman, memid_aml_environ, copy);
107853e202c1Schristos }
107953e202c1Schristos 
108053e202c1Schristos static struct aml_name *
aml_parse_defelse(struct aml_environ * env,int indent,int num)108153e202c1Schristos aml_parse_defelse(struct aml_environ *env, int indent, int num)
108253e202c1Schristos {
108353e202c1Schristos 	u_int8_t	*start, *end, *oend;
108453e202c1Schristos 	u_int32_t	pkglength;
108553e202c1Schristos 	struct	aml_name *aname;
108653e202c1Schristos 
108753e202c1Schristos 	start = env->dp;
108853e202c1Schristos 	pkglength = aml_parse_pkglength(env);
108953e202c1Schristos 	oend = env->end;
109053e202c1Schristos 	env->end = end = start + pkglength;
109153e202c1Schristos 	aname = NULL;
109253e202c1Schristos 
109353e202c1Schristos 	AML_DEBUGPRINT("Else {\n");
109453e202c1Schristos 	if (num == 0) {
109553e202c1Schristos 		aname = aml_parse_objectlist(env, indent + 1);
109653e202c1Schristos 		aml_print_indent(indent);
109753e202c1Schristos 	}
109853e202c1Schristos 	AML_DEBUGPRINT("}");
109953e202c1Schristos 
110053e202c1Schristos 	env->dp = end;
110153e202c1Schristos 	env->end = oend;
110253e202c1Schristos 	return (aname);
110353e202c1Schristos }
110453e202c1Schristos 
110553e202c1Schristos static struct aml_name *
aml_parse_defif(struct aml_environ * env,int indent)110653e202c1Schristos aml_parse_defif(struct aml_environ *env, int indent)
110753e202c1Schristos {
110853e202c1Schristos 	u_int8_t	*start, *end, *oend;
110953e202c1Schristos 	u_int32_t	pkglength;
111053e202c1Schristos 	int	num;
111153e202c1Schristos 	struct	aml_name *aname, *aname1;
111253e202c1Schristos 
111353e202c1Schristos 	start = env->dp;
111453e202c1Schristos 	pkglength = aml_parse_pkglength(env);
111553e202c1Schristos 	aname = NULL;
111653e202c1Schristos 
111753e202c1Schristos 	AML_DEBUGPRINT("If(");
111853e202c1Schristos 	num = aml_objtonum(env, aml_eval_name
111953e202c1Schristos 	    (env, aml_parse_termobj(env, indent)));
112053e202c1Schristos 	oend = env->end;
112153e202c1Schristos 	end = start + pkglength;
112253e202c1Schristos 	AML_DEBUGPRINT(")");
112353e202c1Schristos 	if (num) {
112453e202c1Schristos 		AML_DEBUGPRINT("{\n");
112553e202c1Schristos 		env->end = end;
112653e202c1Schristos 		aname = aml_parse_objectlist(env, indent + 1);
112753e202c1Schristos 		aml_print_indent(indent);
112853e202c1Schristos 		AML_DEBUGPRINT("}");
112953e202c1Schristos 	}
113053e202c1Schristos 	env->dp = end;
113153e202c1Schristos 	env->end = oend;
113253e202c1Schristos 	if ((end < oend) && *(env->dp) == 0xa1) {
113353e202c1Schristos 		env->dp++;
113453e202c1Schristos 		aname1 = aml_parse_defelse(env, indent, num);
113553e202c1Schristos 		aname = (num == 0) ? aname1 : aname;
113653e202c1Schristos 	}
113753e202c1Schristos 	return (aname);
113853e202c1Schristos }
113953e202c1Schristos 
114053e202c1Schristos static struct aml_name *
aml_parse_defwhile(struct aml_environ * env,int indent)114153e202c1Schristos aml_parse_defwhile(struct aml_environ *env, int indent)
114253e202c1Schristos {
114353e202c1Schristos 	u_int8_t	*start, *end, *oend;
114453e202c1Schristos 	u_int32_t	pkglength;
114553e202c1Schristos 	int	num;
114653e202c1Schristos 	struct	aml_name *aname;
114753e202c1Schristos 
114853e202c1Schristos 	start = env->dp;
114953e202c1Schristos 	pkglength = aml_parse_pkglength(env);
115053e202c1Schristos 	oend = env->end;
115153e202c1Schristos 	end = start + pkglength;
115253e202c1Schristos 	aname = NULL;
115353e202c1Schristos 	for (;;) {
115453e202c1Schristos 		env->dp = start;
115553e202c1Schristos 		aml_parse_pkglength(env);
115653e202c1Schristos 		AML_DEBUGPRINT("While(");
115753e202c1Schristos 		num = aml_objtonum(env, aml_eval_name
115853e202c1Schristos 		    (env, aml_parse_termobj(env, indent)));
115953e202c1Schristos 		AML_DEBUGPRINT(")");
116053e202c1Schristos 		if (num == 0) {
116153e202c1Schristos 			break;
116253e202c1Schristos 		}
116353e202c1Schristos 		AML_DEBUGPRINT(" {\n");
116453e202c1Schristos 		env->end = end;
116553e202c1Schristos 		aname = aml_parse_objectlist(env, indent + 1);
116653e202c1Schristos 		if (env->stat == aml_stat_step) {
116753e202c1Schristos 			AML_DEBUGGER(env, env);
116853e202c1Schristos 			continue;
116953e202c1Schristos 		}
117053e202c1Schristos 		if (env->stat != aml_stat_none)
117153e202c1Schristos 			break;
117253e202c1Schristos 		aml_print_indent(indent);
117353e202c1Schristos 		AML_DEBUGPRINT("}");
117453e202c1Schristos 	}
117553e202c1Schristos 	AML_DEBUGPRINT("\n");
117653e202c1Schristos 	env->dp = end;
117753e202c1Schristos 	env->end = oend;
117853e202c1Schristos 	if (env->stat == aml_stat_break) {
117953e202c1Schristos 		env->stat = aml_stat_none;
118053e202c1Schristos 		aname = NULL;
118153e202c1Schristos 	}
118253e202c1Schristos 	return (aname);
118353e202c1Schristos }
118453e202c1Schristos 
118553e202c1Schristos static void
aml_parse_defmutex(struct aml_environ * env,int indent)118653e202c1Schristos aml_parse_defmutex(struct aml_environ *env, int indent)
118753e202c1Schristos {
118853e202c1Schristos 	char	*name;
118953e202c1Schristos 	struct	aml_name *aname;
119053e202c1Schristos 	struct	aml_mutex *mut;
119153e202c1Schristos 
119253e202c1Schristos 	/* MutexOp */
119353e202c1Schristos 	AML_DEBUGPRINT("Mutex(");
119453e202c1Schristos 	name = (char *)aml_parse_namestring(env);
119553e202c1Schristos 	aml_print_namestring((unsigned char *)name);
119653e202c1Schristos 	AML_CREATE_NAME(aname, env, (unsigned char *)name,);
119753e202c1Schristos 	if (aname->property != NULL) {
119853e202c1Schristos 		env->stat = aml_stat_panic;
119953e202c1Schristos 		AML_DEBUGPRINT("Already Defined \n");
120053e202c1Schristos 		return;
120153e202c1Schristos 	}
120253e202c1Schristos 	AML_ALLOC_OBJECT(aname->property, env, aml_t_mutex,);
120353e202c1Schristos 	mut = &aname->property->mutex;
120453e202c1Schristos 	mut->level = *env->dp++;
120553e202c1Schristos 	STAILQ_INIT(&mut->queue);
120653e202c1Schristos 	AML_DEBUGPRINT(", %d)", mut->level);
120753e202c1Schristos }
120853e202c1Schristos 
120953e202c1Schristos static void
aml_createfield_generic(struct aml_environ * env,union aml_object * srcbuf,int idx,int len,char * newname)121053e202c1Schristos aml_createfield_generic(struct aml_environ *env,
121153e202c1Schristos     union aml_object *srcbuf, int idx,
121253e202c1Schristos     int len, char *newname)
121353e202c1Schristos {
121453e202c1Schristos 	struct	aml_bufferfield *field;
121553e202c1Schristos 	struct	aml_name *aname;
121653e202c1Schristos 
121753e202c1Schristos 	if (srcbuf == NULL || srcbuf->type != aml_t_buffer) {
121853e202c1Schristos 		AML_DEBUGPRINT("Not Buffer assigned,");
121953e202c1Schristos 		env->stat = aml_stat_panic;
122053e202c1Schristos 		return;
122153e202c1Schristos 	}
122253e202c1Schristos 	AML_CREATE_NAME(aname, env, (unsigned char *)newname,);
122353e202c1Schristos 	if (aname->property != NULL) {
122453e202c1Schristos 		env->stat = aml_stat_panic;
122553e202c1Schristos 		AML_DEBUGPRINT("Already Defined \n");
122653e202c1Schristos 		return;
122753e202c1Schristos 	}
122853e202c1Schristos 	AML_ALLOC_OBJECT(aname->property, env, aml_t_bufferfield,);
122953e202c1Schristos 	field = &aname->property->bfld;
123053e202c1Schristos 	field->bitoffset = idx;
123153e202c1Schristos 	field->bitlen = len;
123253e202c1Schristos 	field->origin = srcbuf->buffer.data;
123353e202c1Schristos }
123453e202c1Schristos 
123553e202c1Schristos static void
aml_parse_defcreatefield(struct aml_environ * env,int indent)123653e202c1Schristos aml_parse_defcreatefield(struct aml_environ *env, int indent)
123753e202c1Schristos {
123853e202c1Schristos 	int	idx, len;
123953e202c1Schristos 	char	*newname;
124053e202c1Schristos 	union	aml_object *obj, *srcbuf;
124153e202c1Schristos 
124253e202c1Schristos 	/* CreateFieldOp */
124353e202c1Schristos 	AML_DEBUGPRINT("CreateField(");
124453e202c1Schristos 	srcbuf = aml_eval_name(env, aml_parse_termobj(env, indent));
124553e202c1Schristos 	if (srcbuf == &env->tempobject) {
124653e202c1Schristos 		AML_DEBUGPRINT("NONAMED BUFFER\n");
124753e202c1Schristos 		env->stat = aml_stat_panic;
124853e202c1Schristos 		return;
124953e202c1Schristos 	}
125053e202c1Schristos 	AML_DEBUGPRINT(", ");
125153e202c1Schristos 	obj = aml_eval_name(env, aml_parse_termobj(env, indent));
125253e202c1Schristos 	idx = aml_objtonum(env, obj);
125353e202c1Schristos 	AML_DEBUGPRINT(", ");
125453e202c1Schristos 	obj = aml_eval_name(env, aml_parse_termobj(env, indent));
125553e202c1Schristos 	len = aml_objtonum(env, obj);
125653e202c1Schristos 	AML_DEBUGPRINT(", ");
125753e202c1Schristos 	newname = (char *)aml_parse_namestring(env);
125853e202c1Schristos 	aml_print_namestring((unsigned char *)newname);
125953e202c1Schristos 	aml_createfield_generic(env, srcbuf, idx, len, newname);
126053e202c1Schristos 	AML_DEBUGPRINT(") ");
126153e202c1Schristos }
126253e202c1Schristos 
126353e202c1Schristos /*
126453e202c1Schristos  * Returns Named object or parser buffer. The object need not be free because
126553e202c1Schristos  * it returns preallocated buffer in env or Contain of named object.  If You
126653e202c1Schristos  * need to preserve object, create a copy and then store.  And The object
126753e202c1Schristos  * returned from this function is not valid after another call is
126853e202c1Schristos  * shared, tempolary buffer may be shared.
126953e202c1Schristos  */
127053e202c1Schristos struct aml_name *
aml_parse_termobj(struct aml_environ * env,int indent)127153e202c1Schristos aml_parse_termobj(struct aml_environ *env, int indent)
127253e202c1Schristos {
127353e202c1Schristos 	u_int8_t	opcode;
127453e202c1Schristos 	u_int8_t	*name;
127553e202c1Schristos 	int	value;
127653e202c1Schristos 	int	num1, num2;
127753e202c1Schristos 	int	len;
127853e202c1Schristos 	int	match1, match2, i, pkgval, start;
127953e202c1Schristos 	int	widthindex, idx;
128053e202c1Schristos 	char	*newname;
128153e202c1Schristos 	struct	aml_name *aname;
128253e202c1Schristos 	struct	aml_name *destname1, *destname2;
128353e202c1Schristos 	struct	aml_name *tmpname, *srcname;
128453e202c1Schristos 	struct	aml_name *src;
128553e202c1Schristos 	union	aml_object *ret;
128653e202c1Schristos 	union	aml_object *tmpobj;
128753e202c1Schristos 	union	aml_object anum;
128853e202c1Schristos 	union	aml_object *objref;
128953e202c1Schristos 	union	aml_object *srcobj;
129053e202c1Schristos 	union	aml_object *obj;
129153e202c1Schristos 	union	aml_object *srcbuf;
129253e202c1Schristos 	static int	widthtbl[4] = {32, 16, 8, 1};
129353e202c1Schristos 	const char	*opname[4] = {"CreateDWordField", "CreateWordField",
129453e202c1Schristos 				      "CreateByteField", "CreateBitField"};
129553e202c1Schristos 
129653e202c1Schristos 	aname = &env->tempname;
129753e202c1Schristos 	ret = &env->tempobject;
129853e202c1Schristos 	anum.type = aml_t_num;
129953e202c1Schristos 	aname->property = ret;
130053e202c1Schristos 	aml_free_objectcontent(ret);
130153e202c1Schristos 	if (env->stat == aml_stat_panic) {
130253e202c1Schristos 		/*
1303*a41f6947Sandvar 		 * If previously parser panic , parsing next instruction is
130453e202c1Schristos 		 * prohibited.
130553e202c1Schristos 		 */
130653e202c1Schristos 		return (NULL);
130753e202c1Schristos 	}
130853e202c1Schristos 	aname = NULL;
130953e202c1Schristos 	opcode = *env->dp++;
131053e202c1Schristos 	switch (opcode) {
131153e202c1Schristos 	case '\\':
131253e202c1Schristos 	case '^':
131353e202c1Schristos 	case 'A' ... 'Z':
131453e202c1Schristos 	case '_':
131553e202c1Schristos 	case '.':
131653e202c1Schristos 	case '/':
131753e202c1Schristos 		env->dp--;
131853e202c1Schristos 		ret->type = aml_t_namestr;
131953e202c1Schristos 		ret->nstr.dp = aml_parse_namestring(env);
132053e202c1Schristos 		aml_print_namestring(ret->nstr.dp);
132153e202c1Schristos 		aname = &env->tempname;
132253e202c1Schristos 		break;
132353e202c1Schristos 	case 0x0a:		/* BytePrefix */
132453e202c1Schristos 		ret->type = aml_t_num;
132553e202c1Schristos 		value = aml_parse_bytedata(env);
132653e202c1Schristos 		ret->num.number = value;
132753e202c1Schristos 		AML_DEBUGPRINT("0x%x", value);
132853e202c1Schristos 		aname = &env->tempname;
132953e202c1Schristos 		break;
133053e202c1Schristos 	case 0x0b:		/* WordPrefix */
133153e202c1Schristos 		ret->type = aml_t_num;
133253e202c1Schristos 		value = aml_parse_worddata(env);
133353e202c1Schristos 		ret->num.number = value;
133453e202c1Schristos 		AML_DEBUGPRINT("0x%x", value);
133553e202c1Schristos 		aname = &env->tempname;
133653e202c1Schristos 		break;
133753e202c1Schristos 	case 0x0c:		/* DWordPrefix */
133853e202c1Schristos 		ret->type = aml_t_num;
133953e202c1Schristos 		value = aml_parse_dworddata(env);
134053e202c1Schristos 		ret->num.number = value;
134153e202c1Schristos 		AML_DEBUGPRINT("0x%x", value);
134253e202c1Schristos 		aname = &env->tempname;
134353e202c1Schristos 		break;
134453e202c1Schristos 	case 0x0d:		/* StringPrefix */
134553e202c1Schristos 		ret->type = aml_t_string;
134653e202c1Schristos 		ret->str.string = env->dp;
134753e202c1Schristos 		len = strlen((const char *)env->dp);
134853e202c1Schristos 		ret->str.needfree = 0;
134953e202c1Schristos 		AML_DEBUGPRINT("\"%s\"", (const char *)ret->str.string);
135053e202c1Schristos 		env->dp += (len + 1);
135153e202c1Schristos 		aname = &env->tempname;
135253e202c1Schristos 		break;
135353e202c1Schristos 	case 0x00:		/* ZeroOp */
135453e202c1Schristos 		ret->type = aml_t_num;
135553e202c1Schristos 		ret->num.number = 0;
135653e202c1Schristos 		ret->num.constant = 1;
135753e202c1Schristos 		AML_DEBUGPRINT("Zero");
135853e202c1Schristos 		aname = &env->tempname;
135953e202c1Schristos 		break;
136053e202c1Schristos 	case 0x01:		/* OneOp */
136153e202c1Schristos 		ret->type = aml_t_num;
136253e202c1Schristos 		ret->num.number = 1;
136353e202c1Schristos 		ret->num.constant = 1;
136453e202c1Schristos 		AML_DEBUGPRINT("One");
136553e202c1Schristos 		aname = &env->tempname;
136653e202c1Schristos 		break;
136753e202c1Schristos 	case 0xff:		/* OnesOp */
136853e202c1Schristos 		ret->type = aml_t_num;
136953e202c1Schristos 		ret->num.number = 0xffffffff;
137053e202c1Schristos 		ret->num.constant = 1;
137153e202c1Schristos 		AML_DEBUGPRINT("Ones");
137253e202c1Schristos 		aname = &env->tempname;
137353e202c1Schristos 		break;
137453e202c1Schristos 	case 0x06:		/* AliasOp */
137553e202c1Schristos 		AML_DEBUGPRINT("Alias(");
137653e202c1Schristos 		tmpname = aml_parse_termobj(env, indent);
137753e202c1Schristos 		if (env->stat == aml_stat_panic) {
137853e202c1Schristos 			return (NULL);
137953e202c1Schristos 		}
138053e202c1Schristos 		if (tmpname->property == NULL ||
138153e202c1Schristos 		    tmpname->property->type != aml_t_namestr) {
138253e202c1Schristos 			env->stat = aml_stat_panic;
138353e202c1Schristos 			return (NULL);
138453e202c1Schristos 		}
138553e202c1Schristos 		/*
138653e202c1Schristos 		 * XXX if srcname is deleted after this object, what
138753e202c1Schristos 		 * shall I do?
138853e202c1Schristos 		 */
138953e202c1Schristos 		srcname = aml_search_name(env, tmpname->property->nstr.dp);
139053e202c1Schristos 		AML_DEBUGPRINT(", ");
139153e202c1Schristos 		name = aml_parse_namestring(env);
139253e202c1Schristos 		aml_print_namestring(name);
139353e202c1Schristos 		AML_CREATE_NAME(aname, env, name, 0);
139453e202c1Schristos 		if (aname->property != NULL) {
139553e202c1Schristos 			env->stat = aml_stat_panic;
139653e202c1Schristos 			AML_DEBUGPRINT("Already Defined \n");
139753e202c1Schristos 			aml_print_curname(aname);
139853e202c1Schristos 			return (NULL);
139953e202c1Schristos 		}
140053e202c1Schristos 		AML_ALLOC_OBJECT(aname->property, env, aml_t_objref, NULL);
140153e202c1Schristos 		objref = aname->property;
140253e202c1Schristos 		objref->objref.nameref = srcname;
140353e202c1Schristos 		objref->objref.ref = srcname->property;
140453e202c1Schristos 		objref->objref.offset = -1;
140553e202c1Schristos 		objref->objref.alias = 1;	/* Yes, this is an alias */
140653e202c1Schristos 		AML_DEBUGPRINT(")");
140753e202c1Schristos 		/* shut the interpreter up during the namespace initializing */
140853e202c1Schristos 		return (NULL);
140953e202c1Schristos 	case 0x08:		/* NameOp */
141053e202c1Schristos 		AML_DEBUGPRINT("Name(");
141153e202c1Schristos 		name = aml_parse_namestring(env);
141253e202c1Schristos 		aml_print_namestring(name);
141353e202c1Schristos 		AML_CREATE_NAME(aname, env, name, 0);
141453e202c1Schristos 		if (env->stat == aml_stat_panic) {
141553e202c1Schristos 			AML_DEBUGPRINT("Already Defined \n");
141653e202c1Schristos 			aml_print_curname(aname);
141753e202c1Schristos 			return (NULL);
141853e202c1Schristos 		}
141953e202c1Schristos 		AML_DEBUGPRINT(", ");
142053e202c1Schristos 		AML_COPY_OBJECT(aname->property, env,
142153e202c1Schristos 		    aml_eval_name(env,
142253e202c1Schristos 			aml_parse_termobj(env, indent)),
142353e202c1Schristos 		    NULL);
142453e202c1Schristos 		AML_DEBUGPRINT(")");
142553e202c1Schristos 		break;
142653e202c1Schristos 	case 0x10:		/* ScopeOp */
142753e202c1Schristos 		aml_parse_defscope(env, indent);
142853e202c1Schristos 		break;
142953e202c1Schristos 	case 0x11:		/* BufferOp */
143053e202c1Schristos 		aname = &env->tempname;
143153e202c1Schristos 		aname->property = aml_parse_defbuffer(env, indent);
143253e202c1Schristos 		break;
143353e202c1Schristos 	case 0x12:		/* PackageOp */
143453e202c1Schristos 		aname = &env->tempname;
143553e202c1Schristos 		aname->property = aml_parse_defpackage(env, indent);
143653e202c1Schristos 		break;
143753e202c1Schristos 	case 0x14:		/* MethodOp */
143853e202c1Schristos 		aml_parse_defmethod(env, indent);
143953e202c1Schristos 		break;
144053e202c1Schristos 	case 0x5b:		/* ExtOpPrefix */
144153e202c1Schristos 		opcode = *env->dp++;
144253e202c1Schristos 		switch (opcode) {
144353e202c1Schristos 		case 0x01:
144453e202c1Schristos 			aml_parse_defmutex(env, indent);
144553e202c1Schristos 			break;
144653e202c1Schristos 		case 0x02:	/* EventOp */
144753e202c1Schristos 			AML_DEBUGPRINT("Event(");
144853e202c1Schristos 			name = aml_parse_namestring(env);
144953e202c1Schristos 			aml_print_namestring(name);
145053e202c1Schristos 			AML_CREATE_NAME(aname, env, name, 0);
145153e202c1Schristos 			if (aname->property != NULL) {
145253e202c1Schristos 				env->stat = aml_stat_panic;
145353e202c1Schristos 				AML_DEBUGPRINT("Already Defined \n");
145453e202c1Schristos 				return (NULL);
145553e202c1Schristos 			}
145653e202c1Schristos 			AML_ALLOC_OBJECT(aname->property, env, aml_t_event, NULL);
145753e202c1Schristos 			AML_DEBUGPRINT(")");
145853e202c1Schristos 			return (NULL);
145953e202c1Schristos 			break;
146053e202c1Schristos 		case 0x12:	/* CondRefOfOp */
146153e202c1Schristos 			AML_DEBUGPRINT("CondRefOf(");
146253e202c1Schristos 			src = aml_parse_termobj(env, indent);
146353e202c1Schristos 			AML_DEBUGPRINT(", ");
146453e202c1Schristos 			if (src == &env->tempname || src == NULL) {
146553e202c1Schristos 				aml_parse_termobj(env, indent);
146653e202c1Schristos 				AML_DEBUGPRINT(")");
146753e202c1Schristos 				anum.num.number = 0xffffffff;
146853e202c1Schristos 				env->tempobject.num = anum.num;
146953e202c1Schristos 				aname = &env->tempname;
147053e202c1Schristos 				break;
147153e202c1Schristos 			}
147253e202c1Schristos 			AML_ALLOC_OBJECT(objref, env, aml_t_objref, NULL);
147353e202c1Schristos 			if (src->property == NULL ||
147453e202c1Schristos 			    src->property->type != aml_t_namestr) {
147553e202c1Schristos 				objref->objref.nameref = src;
147653e202c1Schristos 			} else {
147753e202c1Schristos 				objref->objref.nameref = aml_create_local_object();
147853e202c1Schristos 			}
147953e202c1Schristos 			objref->objref.ref = src->property;
148053e202c1Schristos 			objref->objref.offset = -1;	/* different from IndexOp */
148153e202c1Schristos 
148253e202c1Schristos 			destname1 = aml_parse_termobj(env, indent);
148353e202c1Schristos 			aml_store_to_name(env, objref, destname1);
148453e202c1Schristos 			anum.num.number = 0;
148553e202c1Schristos 			env->tempobject.num = anum.num;
148653e202c1Schristos 			aname = &env->tempname;
148753e202c1Schristos 			AML_DEBUGPRINT(")");
148853e202c1Schristos 			break;
148953e202c1Schristos 		case 0x13:
149053e202c1Schristos 			aml_parse_defcreatefield(env, indent);
149153e202c1Schristos 			break;
149253e202c1Schristos 		case 0x20:	/* LoadOp *//* XXX Not Impremented */
149353e202c1Schristos 			AML_DEBUGPRINT("Load(");
149453e202c1Schristos 			aml_parse_termobj(env, indent);
149553e202c1Schristos 			AML_DEBUGPRINT(", ");
149653e202c1Schristos 			aml_parse_termobj(env, indent);
149753e202c1Schristos 			AML_DEBUGPRINT(")");
149853e202c1Schristos 			break;
149953e202c1Schristos 		case 0x21:	/* StallOp */
150053e202c1Schristos 			AML_DEBUGPRINT("Stall(");
150153e202c1Schristos 			num1 = aml_objtonum(env, aml_eval_name(env,
150253e202c1Schristos 			    aml_parse_termobj(env, indent)));
150353e202c1Schristos 			AML_DEBUGPRINT(")");
150453e202c1Schristos 			AML_STALL(num1);
150553e202c1Schristos 			break;
150653e202c1Schristos 		case 0x22:	/* SleepOp */
150753e202c1Schristos 			AML_DEBUGPRINT("Sleep(");
150853e202c1Schristos 			num1 = aml_objtonum(env, aml_eval_name(env,
150953e202c1Schristos 			    aml_parse_termobj(env, indent)));
151053e202c1Schristos 			AML_SLEEP(0, num1);
151153e202c1Schristos 			AML_DEBUGPRINT(")");
151253e202c1Schristos 			break;
151353e202c1Schristos 		case 0x23:	/* AcquireOp *//* XXX Not yet */
151453e202c1Schristos 			AML_DEBUGPRINT("Acquire(");
151553e202c1Schristos 			aml_parse_termobj(env, indent);
151653e202c1Schristos 			AML_DEBUGPRINT(", 0x%x)", aml_parse_worddata(env));
151753e202c1Schristos 			break;
151853e202c1Schristos 		case 0x24:	/* SignalOp *//* XXX Not yet */
151953e202c1Schristos 			AML_DEBUGPRINT("Signal(");
152053e202c1Schristos 			aml_parse_termobj(env, indent);
152153e202c1Schristos 			AML_DEBUGPRINT(")");
152253e202c1Schristos 			break;
152353e202c1Schristos 		case 0x25:	/* WaitOp *//* XXX Not yet impremented */
152453e202c1Schristos 			AML_DEBUGPRINT("Wait(");
152553e202c1Schristos 			aml_parse_termobj(env, indent);
152653e202c1Schristos 			AML_DEBUGPRINT(", ");
152753e202c1Schristos 			aml_parse_termobj(env, indent);
152853e202c1Schristos 			AML_DEBUGPRINT(")");
152953e202c1Schristos 			break;
153053e202c1Schristos 		case 0x26:	/* ResetOp *//* XXX Not yet impremented */
153153e202c1Schristos 			AML_DEBUGPRINT("Reset(");
153253e202c1Schristos 			aml_parse_termobj(env, indent);
153353e202c1Schristos 			AML_DEBUGPRINT(")");
153453e202c1Schristos 			break;
153553e202c1Schristos 		case 0x27:	/* ReleaseOp *//* XXX Not yet impremented */
153653e202c1Schristos 			AML_DEBUGPRINT("Release(");
153753e202c1Schristos 			aml_parse_termobj(env, indent);
153853e202c1Schristos 			AML_DEBUGPRINT(")");
153953e202c1Schristos 			break;
154053e202c1Schristos #define NUMOP2(opname, operation) do {					\
154153e202c1Schristos 	AML_DEBUGPRINT(opname);						\
154253e202c1Schristos 	AML_DEBUGPRINT("(");						\
154353e202c1Schristos 	num1 = aml_objtonum(env, aml_eval_name(env,			\
154453e202c1Schristos 	    aml_parse_termobj(env, indent)));				\
154553e202c1Schristos 	AML_DEBUGPRINT(", ");						\
154653e202c1Schristos 	anum.num.number = operation (num1);				\
154753e202c1Schristos 	destname1 = aml_parse_termobj(env, indent);			\
154853e202c1Schristos 	AML_DEBUGPRINT(")");						\
154953e202c1Schristos 	aml_store_to_name(env, &anum, destname1);			\
155053e202c1Schristos 	env->tempobject.num = anum.num;					\
155153e202c1Schristos 	env->tempname.property = &env->tempobject;			\
155253e202c1Schristos 	aname = &env->tempname;						\
155353e202c1Schristos } while(0)
155453e202c1Schristos 
155553e202c1Schristos 		case 0x28:	/* FromBCDOp */
155653e202c1Schristos 			NUMOP2("FromBCD", frombcd);
155753e202c1Schristos 			break;
155853e202c1Schristos 		case 0x29:	/* ToBCDOp */
155953e202c1Schristos 			NUMOP2("ToBCD", tobcd);
156053e202c1Schristos 			break;
156153e202c1Schristos 		case 0x2a:	/* UnloadOp *//* XXX Not yet impremented */
156253e202c1Schristos 			AML_DEBUGPRINT("Unload(");
156353e202c1Schristos 			aml_parse_termobj(env, indent);
156453e202c1Schristos 			AML_DEBUGPRINT(")");
156553e202c1Schristos 			break;
156653e202c1Schristos 		case 0x30:
156753e202c1Schristos 			env->tempobject.type = aml_t_num;
156853e202c1Schristos 			env->tempobject.num.number = 0;
156953e202c1Schristos 			env->tempobject.num.constant = 1;
157053e202c1Schristos 			AML_DEBUGPRINT("Revision");
157153e202c1Schristos 			break;
157253e202c1Schristos 		case 0x31:
157353e202c1Schristos 			env->tempobject.type = aml_t_debug;
157453e202c1Schristos 			aname = &env->tempname;
157553e202c1Schristos 			AML_DEBUGPRINT("Debug");
157653e202c1Schristos 			break;
157753e202c1Schristos 		case 0x32:	/* FatalOp */
157853e202c1Schristos 			AML_DEBUGPRINT("Fatal(");
157953e202c1Schristos 			AML_DEBUGPRINT("0x%x, ", aml_parse_bytedata(env));
158053e202c1Schristos 			AML_DEBUGPRINT("0x%x, ", aml_parse_dworddata(env));
158153e202c1Schristos 			aml_parse_termobj(env, indent);
158253e202c1Schristos 			env->stat = aml_stat_panic;
158353e202c1Schristos 			AML_DEBUGPRINT(")");
158453e202c1Schristos 			break;
158553e202c1Schristos 		case 0x80:	/* OpRegionOp */
158653e202c1Schristos 			aml_parse_defopregion(env, indent);
158753e202c1Schristos 			break;
158853e202c1Schristos 		case 0x81:	/* FieldOp */
158953e202c1Schristos 			aml_parse_deffield(env, indent);
159053e202c1Schristos 			break;
159153e202c1Schristos 		case 0x82:	/* DeviceOp */
159253e202c1Schristos 			aml_parse_defdevice(env, indent);
159353e202c1Schristos 			break;
159453e202c1Schristos 		case 0x83:	/* ProcessorOp */
159553e202c1Schristos 			aml_parse_defprocessor(env, indent);
159653e202c1Schristos 			break;
159753e202c1Schristos 		case 0x84:	/* PowerResOp */
159853e202c1Schristos 			aml_parse_defpowerres(env, indent);
159953e202c1Schristos 			break;
160053e202c1Schristos 		case 0x85:	/* ThermalZoneOp */
160153e202c1Schristos 			aml_parse_defthermalzone(env, indent);
160253e202c1Schristos 			break;
160353e202c1Schristos 		case 0x86:	/* IndexFieldOp */
160453e202c1Schristos 			aml_parse_defindexfield(env, indent);
160553e202c1Schristos 			break;
160653e202c1Schristos 		case 0x87:	/* BankFieldOp */
160753e202c1Schristos 			aml_parse_defbankfield(env, indent);
160853e202c1Schristos 			break;
160953e202c1Schristos 		default:
161053e202c1Schristos 			AML_SYSERRX(1, "strange opcode 0x5b, 0x%x\n", opcode);
161153e202c1Schristos 			AML_SYSABORT();
161253e202c1Schristos 		}
161353e202c1Schristos 		break;
161453e202c1Schristos 	case 0x68 ... 0x6e:	/* ArgN */
161553e202c1Schristos 		AML_DEBUGPRINT("Arg%d", opcode - 0x68);
161653e202c1Schristos 		return (aml_local_stack_getArgX(NULL, opcode - 0x68));
161753e202c1Schristos 		break;
161853e202c1Schristos 	case 0x60 ... 0x67:
161953e202c1Schristos 		AML_DEBUGPRINT("Local%d", opcode - 0x60);
162053e202c1Schristos 		return (aml_local_stack_getLocalX(opcode - 0x60));
162153e202c1Schristos 		break;
162253e202c1Schristos 	case 0x70:		/* StoreOp */
162353e202c1Schristos 		AML_DEBUGPRINT("Store(");
162453e202c1Schristos 		aname = aml_create_local_object();
162553e202c1Schristos 		AML_COPY_OBJECT(tmpobj, env,
162653e202c1Schristos 		    aml_eval_name(env,	aml_parse_termobj(env, indent)), NULL);
162753e202c1Schristos 		aname->property = tmpobj;
162853e202c1Schristos 		AML_DEBUGPRINT(", ");
162953e202c1Schristos 		destname1 = aml_parse_termobj(env, indent);
163053e202c1Schristos 		AML_DEBUGPRINT(")");
163153e202c1Schristos 		/* XXX
163253e202c1Schristos 		 * temporary object may change during aml_store_to_name()
163353e202c1Schristos 		 * operation, so we make a copy of it on stack.
163453e202c1Schristos 		 */
163553e202c1Schristos 		if (destname1 == &env->tempname &&
163653e202c1Schristos 		    destname1->property == &env->tempobject) {
163753e202c1Schristos 			destname1 = aml_create_local_object();
163853e202c1Schristos 			AML_COPY_OBJECT(destname1->property, env,
163953e202c1Schristos 			    &env->tempobject, NULL);
164053e202c1Schristos 		}
164153e202c1Schristos 		aml_store_to_name(env, tmpobj, destname1);
164253e202c1Schristos 		if (env->stat == aml_stat_panic) {
164353e202c1Schristos 			AML_DEBUGPRINT("StoreOp failed");
164453e202c1Schristos 			return (NULL);
164553e202c1Schristos 		}
164653e202c1Schristos 		aname = aml_create_local_object();
164753e202c1Schristos 		AML_COPY_OBJECT(tmpobj, env, destname1->property, NULL);
164853e202c1Schristos 		aname->property = tmpobj;
164953e202c1Schristos 		if (tmpobj == NULL) {
165053e202c1Schristos 			printf("???");
165153e202c1Schristos 			break;
165253e202c1Schristos 		}
165353e202c1Schristos 		break;
165453e202c1Schristos 	case 0x71:		/* RefOfOp */
165553e202c1Schristos 		AML_DEBUGPRINT("RefOf(");
165653e202c1Schristos 		src = aml_parse_termobj(env, indent);
165753e202c1Schristos 		AML_DEBUGPRINT(")");
165853e202c1Schristos 
165953e202c1Schristos 		aname = aml_create_local_object();
166053e202c1Schristos 		AML_ALLOC_OBJECT(aname->property, env, aml_t_objref, NULL);
166153e202c1Schristos 		objref = aname->property;
166253e202c1Schristos 		if (src->property == NULL ||
166353e202c1Schristos 		    src->property->type != aml_t_namestr) {
166453e202c1Schristos 			objref->objref.nameref = src;
166553e202c1Schristos 		} else {
166653e202c1Schristos 			objref->objref.nameref = aml_create_local_object();
166753e202c1Schristos 		}
166853e202c1Schristos 		objref->objref.ref = src->property;
166953e202c1Schristos 		objref->objref.offset = -1;	/* different from IndexOp */
167053e202c1Schristos 		break;
167153e202c1Schristos 
167253e202c1Schristos #define NUMOP3_2(opname, oparation, ope2) do {				\
167353e202c1Schristos 	AML_DEBUGPRINT(opname);						\
167453e202c1Schristos 	AML_DEBUGPRINT("(");						\
167553e202c1Schristos 	num1 = aml_objtonum(env, aml_eval_name(env,			\
167653e202c1Schristos 	    aml_parse_termobj(env, indent)));				\
167753e202c1Schristos 	AML_DEBUGPRINT(", ");						\
167853e202c1Schristos 	num2 = aml_objtonum(env, aml_eval_name(env,			\
167953e202c1Schristos 	    aml_parse_termobj(env, indent)));				\
168053e202c1Schristos 	AML_DEBUGPRINT(", ");						\
168153e202c1Schristos 	anum.num.number = ope2(num1 oparation num2);			\
168253e202c1Schristos 	destname1 = aml_parse_termobj(env, indent);			\
168353e202c1Schristos 	AML_DEBUGPRINT(")");						\
168453e202c1Schristos 	aml_store_to_name(env, &anum, destname1);			\
168553e202c1Schristos 	env->tempobject.num = anum.num;					\
168653e202c1Schristos 	env->tempname.property = &env->tempobject;			\
168753e202c1Schristos 	aname = &env->tempname;						\
168853e202c1Schristos } while(0)
168953e202c1Schristos 
169053e202c1Schristos #define NUMOP3(opname, operation)	NUMOP3_2(opname, operation, )
169153e202c1Schristos #define NUMOPN3(opname, operation)	NUMOP3_2(opname, operation, ~)
169253e202c1Schristos 
169353e202c1Schristos 	case 0x72:		/* AddOp */
169453e202c1Schristos 		NUMOP3("Add", +);
169553e202c1Schristos 		break;
169653e202c1Schristos 	case 0x73:		/* ConcatOp  */
169753e202c1Schristos 		aname = aml_parse_concatop(env, indent);
169853e202c1Schristos 		break;
169953e202c1Schristos 	case 0x74:		/* SubtractOp */
170053e202c1Schristos 		NUMOP3("Subtract", -);
170153e202c1Schristos 		break;
170253e202c1Schristos 	case 0x75:		/* IncrementOp */
170353e202c1Schristos 		AML_DEBUGPRINT("Increment(");
170453e202c1Schristos 		aname = aml_parse_termobj(env, indent);
170553e202c1Schristos 		num1 = aml_objtonum(env, aml_eval_name(env, aname));
170653e202c1Schristos 		num1++;
170753e202c1Schristos 		anum.num.number = num1;
170853e202c1Schristos 		AML_DEBUGPRINT(")");
170953e202c1Schristos 		aml_store_to_name(env, &anum, aname);
171053e202c1Schristos 		aname = &env->tempname;
171153e202c1Schristos 		env->tempobject.num = anum.num;
171253e202c1Schristos 		break;
171353e202c1Schristos 	case 0x76:		/* DecrementOp */
171453e202c1Schristos 		AML_DEBUGPRINT("Decrement(");
171553e202c1Schristos 		aname = aml_parse_termobj(env, indent);
171653e202c1Schristos 		num1 = aml_objtonum(env, aml_eval_name(env, aname));
171753e202c1Schristos 		num1--;
171853e202c1Schristos 		anum.num.number = num1;
171953e202c1Schristos 		AML_DEBUGPRINT(")");
172053e202c1Schristos 		aml_store_to_name(env, &anum, aname);
172153e202c1Schristos 		aname = &env->tempname;
172253e202c1Schristos 		env->tempobject.num = anum.num;
172353e202c1Schristos 		break;
172453e202c1Schristos 	case 0x77:		/* MultiplyOp */
172553e202c1Schristos 		NUMOP3("Multiply", *);
172653e202c1Schristos 		break;
172753e202c1Schristos 	case 0x78:		/* DivideOp */
172853e202c1Schristos 		AML_DEBUGPRINT("Divide(");
172953e202c1Schristos 		num1 = aml_objtonum(env, aml_eval_name(env,
173053e202c1Schristos 		    aml_parse_termobj(env, indent)));
173153e202c1Schristos 		AML_DEBUGPRINT(", ");
173253e202c1Schristos 		num2 = aml_objtonum(env, aml_eval_name(env,
173353e202c1Schristos 		    aml_parse_termobj(env, indent)));
173453e202c1Schristos 		AML_DEBUGPRINT(", ");
173553e202c1Schristos 		anum.num.number = num1 % num2;
173653e202c1Schristos 		destname1 = aml_parse_termobj(env, indent);
173753e202c1Schristos 		aml_store_to_name(env, &anum, destname1);
173853e202c1Schristos 		AML_DEBUGPRINT(", ");
173953e202c1Schristos 		anum.num.number = num1 / num2;
174053e202c1Schristos 		destname2 = aml_parse_termobj(env, indent);
174153e202c1Schristos 		AML_DEBUGPRINT(")");
174253e202c1Schristos 		aml_store_to_name(env, &anum, destname2);
174353e202c1Schristos 		env->tempobject.num = anum.num;
174453e202c1Schristos 		aname = &env->tempname;
174553e202c1Schristos 		break;
174653e202c1Schristos 	case 0x79:		/* ShiftLeftOp */
174753e202c1Schristos 		NUMOP3("ShiftLeft", <<);
174853e202c1Schristos 		break;
174953e202c1Schristos 	case 0x7a:		/* ShiftRightOp */
175053e202c1Schristos 		NUMOP3("ShiftRight", >>);
175153e202c1Schristos 		break;
175253e202c1Schristos 	case 0x7b:		/* AndOp */
175353e202c1Schristos 		NUMOP3("And", &);
175453e202c1Schristos 		break;
175553e202c1Schristos 	case 0x7c:		/* NAndOp */
175653e202c1Schristos 		NUMOPN3("NAnd", &);
175753e202c1Schristos 		break;
175853e202c1Schristos 	case 0x7d:		/* OrOp */
175953e202c1Schristos 		NUMOP3("Or", |);
176053e202c1Schristos 		break;
176153e202c1Schristos 	case 0x7e:		/* NOrOp */
176253e202c1Schristos 		NUMOPN3("NOr", |);
176353e202c1Schristos 		break;
176453e202c1Schristos 	case 0x7f:		/* XOrOp */
176553e202c1Schristos 		NUMOP3("XOr", ^);
176653e202c1Schristos 		break;
176753e202c1Schristos 	case 0x80:		/* NotOp */
176853e202c1Schristos 		NUMOP2("Not", ~);
176953e202c1Schristos 		break;
177053e202c1Schristos 	case 0x81:		/* FindSetLeftBitOp */
177153e202c1Schristos 		NUMOP2("FindSetLeftBit", findsetleftbit);
177253e202c1Schristos 		break;
177353e202c1Schristos 	case 0x82:		/* FindSetRightBitOp */
177453e202c1Schristos 		NUMOP2("FindSetRightBit", findsetrightbit);
177553e202c1Schristos 		break;
177653e202c1Schristos 	case 0x83:		/* DerefOp */
177753e202c1Schristos 		AML_DEBUGPRINT("DerefOf(");
177853e202c1Schristos 		objref = aml_eval_name(env, aml_parse_termobj(env, indent));
177953e202c1Schristos 		AML_DEBUGPRINT(")");
178053e202c1Schristos 
178153e202c1Schristos 		if (objref->objref.ref == NULL) {
178253e202c1Schristos 			env->tempname.property = objref->objref.ref;
178353e202c1Schristos 			aname = &env->tempname;
178453e202c1Schristos 			break;
178553e202c1Schristos 		}
178653e202c1Schristos 		switch (objref->objref.ref->type) {
178753e202c1Schristos 		case aml_t_package:
178853e202c1Schristos 		case aml_t_buffer:
178953e202c1Schristos 			if (objref->objref.offset < 0) {
179053e202c1Schristos 				env->tempname.property = objref->objref.ref;
179153e202c1Schristos 			} else {
179253e202c1Schristos 				objref->objref.deref = 1;
179353e202c1Schristos 				env->tempname.property = objref;
179453e202c1Schristos 			}
179553e202c1Schristos 			break;
179653e202c1Schristos 		default:
179753e202c1Schristos 			env->tempname.property = objref->objref.ref;
179853e202c1Schristos 			break;
179953e202c1Schristos 		}
180053e202c1Schristos 
180153e202c1Schristos 		aname = &env->tempname;
180253e202c1Schristos 		break;
180353e202c1Schristos 	case 0x86:		/* NotifyOp *//* XXX Not yet impremented */
180453e202c1Schristos 		AML_DEBUGPRINT("Notify(");
180553e202c1Schristos 		aml_parse_termobj(env, indent);
180653e202c1Schristos 		AML_DEBUGPRINT(", ");
180753e202c1Schristos 		aml_parse_termobj(env, indent);
180853e202c1Schristos 		AML_DEBUGPRINT(")");
180953e202c1Schristos 		break;
181053e202c1Schristos 	case 0x87:		/* SizeOfOp */
181153e202c1Schristos 		AML_DEBUGPRINT("SizeOf(");
181253e202c1Schristos 		aname = aml_parse_termobj(env, indent);
181353e202c1Schristos 		tmpobj = aml_eval_name(env, aname);
181453e202c1Schristos 
181553e202c1Schristos 		AML_DEBUGPRINT(")");
181653e202c1Schristos 		num1 = 0;
181753e202c1Schristos 		switch (tmpobj->type) {
181853e202c1Schristos 		case aml_t_buffer:
181953e202c1Schristos 			num1 = tmpobj->buffer.size;
182053e202c1Schristos 			break;
182153e202c1Schristos 		case aml_t_string:
182253e202c1Schristos 			num1 = strlen((const char *)tmpobj->str.string);
182353e202c1Schristos 			break;
182453e202c1Schristos 		case aml_t_package:
182553e202c1Schristos 			num1 = tmpobj->package.elements;
182653e202c1Schristos 			break;
182753e202c1Schristos 		default:
182853e202c1Schristos 			AML_DEBUGPRINT("Args of SizeOf should be "
182953e202c1Schristos 				       "buffer/string/package only\n");
183053e202c1Schristos 			break;
183153e202c1Schristos 		}
183253e202c1Schristos 
183353e202c1Schristos 		anum.num.number = num1;
183453e202c1Schristos 		env->tempobject.num = anum.num;
183553e202c1Schristos 		aname = &env->tempname;
183653e202c1Schristos 		break;
183753e202c1Schristos 	case 0x88:		/* IndexOp */
183853e202c1Schristos 		AML_DEBUGPRINT("Index(");
183953e202c1Schristos 		srcobj = aml_eval_name(env, aml_parse_termobj(env, indent));
184053e202c1Schristos 		AML_DEBUGPRINT(", ");
184153e202c1Schristos 		num1 = aml_objtonum(env, aml_eval_name(env,
184253e202c1Schristos 		    aml_parse_termobj(env, indent)));
184353e202c1Schristos 		AML_DEBUGPRINT(", ");
184453e202c1Schristos 		destname1 = aml_parse_termobj(env, indent);
184553e202c1Schristos 		AML_DEBUGPRINT(")");
184653e202c1Schristos 		aname = aml_create_local_object();
184753e202c1Schristos 		switch (srcobj->type) {
184853e202c1Schristos 		case aml_t_package:
184953e202c1Schristos 		case aml_t_buffer:
185053e202c1Schristos 			AML_ALLOC_OBJECT(objref, env, aml_t_objref, NULL);
185153e202c1Schristos 			aname->property = objref;
185253e202c1Schristos 			objref->objref.ref = srcobj;
185353e202c1Schristos 			objref->objref.offset = num1;
185453e202c1Schristos 			objref->objref.deref = 0;
185553e202c1Schristos 			break;
185653e202c1Schristos 		default:
185753e202c1Schristos 			AML_DEBUGPRINT("Arg0 of Index should be either "
185853e202c1Schristos 				       "buffer or package\n");
185953e202c1Schristos 			return (aname);
186053e202c1Schristos 		}
186153e202c1Schristos 
186253e202c1Schristos 		aml_store_to_name(env, objref, destname1);
186353e202c1Schristos 		break;
186453e202c1Schristos 	case 0x89:		/* MatchOp *//* XXX Not yet Impremented */
186553e202c1Schristos 		AML_DEBUGPRINT("Match(");
186653e202c1Schristos 		AML_COPY_OBJECT(obj, env, aml_eval_name(env,
186753e202c1Schristos 		    aml_parse_termobj(env, indent)), NULL);
186853e202c1Schristos 		if (obj->type != aml_t_package) {
186953e202c1Schristos 			env->stat = aml_stat_panic;
187053e202c1Schristos 			return (NULL);
187153e202c1Schristos 		}
187253e202c1Schristos 		anum.num.number = 0xffffffff;
187353e202c1Schristos 		match1 = *env->dp;
187453e202c1Schristos 		AML_DEBUGPRINT(", %d", *env->dp);
187553e202c1Schristos 		env->dp++;
187653e202c1Schristos 		num1 = aml_objtonum(env, aml_eval_name(env,
187753e202c1Schristos 		    aml_parse_termobj(env, indent)));
187853e202c1Schristos 		match2 = *env->dp;
187953e202c1Schristos 		AML_DEBUGPRINT(", %d", *env->dp);
188053e202c1Schristos 		env->dp++;
188153e202c1Schristos 		num2 = aml_objtonum(env, aml_eval_name(env,
188253e202c1Schristos 		    aml_parse_termobj(env, indent)));
188353e202c1Schristos 		AML_DEBUGPRINT(", ");
188453e202c1Schristos 		start = aml_objtonum(env, aml_eval_name(env,
188553e202c1Schristos 		    aml_parse_termobj(env, indent)));
188653e202c1Schristos 
188753e202c1Schristos #define MATCHOP(opnum, arg1, arg2)	((opnum == 0) ? (1) :		\
188853e202c1Schristos     (opnum == 1) ? ((arg1) == (arg2))	:				\
188953e202c1Schristos     (opnum == 2) ? ((arg1) <= (arg2))	:				\
189053e202c1Schristos     (opnum == 3) ? ((arg1) <  (arg2))	:				\
189153e202c1Schristos     (opnum == 4) ? ((arg1) >= (arg2))	:				\
189253e202c1Schristos     (opnum == 5) ? ((arg1) >  (arg2))	: 0 )
189353e202c1Schristos 
189453e202c1Schristos 		for (i = start; i < obj->package.elements; i++) {
189553e202c1Schristos 			pkgval = aml_objtonum(env, obj->package.objects[i]);
189653e202c1Schristos 			if (MATCHOP(match1, pkgval, num1) &&
189753e202c1Schristos 			    MATCHOP(match2, pkgval, num2)) {
189853e202c1Schristos 				anum.num.number = i;
189953e202c1Schristos 				break;
190053e202c1Schristos 			}
190153e202c1Schristos 		}
190253e202c1Schristos 		AML_DEBUGPRINT(")");
190353e202c1Schristos 		aml_free_object(&obj);
190453e202c1Schristos 		aname = &env->tempname;
190553e202c1Schristos 		env->tempname.property = &env->tempobject;
190653e202c1Schristos 		env->tempobject.num = anum.num;
190753e202c1Schristos 		break;
190853e202c1Schristos #undef MATCHOP
190953e202c1Schristos 	case 0x8a ... 0x8d:	/* CreateDWordFieldOp */
191053e202c1Schristos 		widthindex = *(env->dp - 1) - 0x8a;
191153e202c1Schristos 		AML_DEBUGPRINT("%s(", opname[widthindex]);
191253e202c1Schristos 		srcbuf = aml_eval_name(env, aml_parse_termobj(env, indent));
191353e202c1Schristos 		if (srcbuf == &env->tempobject) {
191453e202c1Schristos 			AML_DEBUGPRINT("NOT NAMEDBUF\n");
191553e202c1Schristos 			env->stat = aml_stat_panic;
191653e202c1Schristos 			return (NULL);
191753e202c1Schristos 		}
191853e202c1Schristos 		AML_DEBUGPRINT(", ");
191953e202c1Schristos 		idx = aml_objtonum(env, aml_eval_name(env,
192053e202c1Schristos 		    aml_parse_termobj(env, indent)));
192153e202c1Schristos 		if (widthindex != 3) {
192253e202c1Schristos 			idx *= 8;
192353e202c1Schristos 		}
192453e202c1Schristos 		AML_DEBUGPRINT(", ");
192553e202c1Schristos 		newname = (char *)aml_parse_namestring(env);
192653e202c1Schristos 		aml_print_namestring((unsigned char *)newname);
192753e202c1Schristos 		aml_createfield_generic(env, srcbuf, idx,
192853e202c1Schristos 		    widthtbl[widthindex], newname);
192953e202c1Schristos 		AML_DEBUGPRINT(")");
193053e202c1Schristos 		break;
193153e202c1Schristos 	case 0x8e:		/* ObjectTypeOp */
193253e202c1Schristos 		AML_DEBUGPRINT("ObjectType(");
193353e202c1Schristos 		aname = aml_parse_termobj(env, indent);
193453e202c1Schristos 		if (aname == NULL) {
193553e202c1Schristos 			env->tempobject.type = aml_t_num;
193653e202c1Schristos 			env->tempobject.num.number = aml_t_null;
193753e202c1Schristos 		} else {
193853e202c1Schristos 			env->tempobject.type = aml_t_num;
193953e202c1Schristos 			env->tempobject.num.number = aname->property->type;
194053e202c1Schristos 		}
194153e202c1Schristos 		aname = &env->tempname;
194253e202c1Schristos 		AML_DEBUGPRINT(")");
194353e202c1Schristos 		break;
194453e202c1Schristos 
194553e202c1Schristos #define CMPOP(opname,operation) do {					\
194653e202c1Schristos 	AML_DEBUGPRINT(opname);						\
194753e202c1Schristos 	AML_DEBUGPRINT("(");						\
194853e202c1Schristos 	num1 = aml_objtonum(env, aml_eval_name(env,			\
194953e202c1Schristos 	    aml_parse_termobj(env, indent)));				\
195053e202c1Schristos 	AML_DEBUGPRINT(", ");						\
195153e202c1Schristos 	num2 = aml_objtonum(env, aml_eval_name(env,			\
195253e202c1Schristos 	    aml_parse_termobj(env, indent)));				\
195353e202c1Schristos 	aname = &env->tempname;						\
195453e202c1Schristos 	env->tempobject.type = aml_t_num;				\
195553e202c1Schristos 	env->tempobject.num.number = (num1 operation num2) ? 0xffffffff : 0;	\
195653e202c1Schristos 	aname->property = &env->tempobject;				\
195753e202c1Schristos 	AML_DEBUGPRINT(")");						\
195853e202c1Schristos } while(0)
195953e202c1Schristos 
196053e202c1Schristos 	case 0x90:
196153e202c1Schristos 		CMPOP("LAnd", &&);
196253e202c1Schristos 		break;
196353e202c1Schristos 	case 0x91:
196453e202c1Schristos 		CMPOP("LOr", ||);
196553e202c1Schristos 		break;
196653e202c1Schristos 	case 0x92:
196753e202c1Schristos 		AML_DEBUGPRINT("LNot(");
196853e202c1Schristos 		num1 = aml_objtonum(env, aml_eval_name(env,
196953e202c1Schristos 		    aml_parse_termobj(env, indent)));
197053e202c1Schristos 		aname = &env->tempname;
197153e202c1Schristos 		env->tempobject.type = aml_t_num;
197253e202c1Schristos 		env->tempobject.num.number = (!num1) ? 0xffffffff : 0;
197353e202c1Schristos 		aname->property = &env->tempobject;
197453e202c1Schristos 		AML_DEBUGPRINT(")");
197553e202c1Schristos 		break;
197653e202c1Schristos 	case 0x93:
197753e202c1Schristos 		CMPOP("LEqual", ==);
197853e202c1Schristos 		break;
197953e202c1Schristos 	case 0x94:
198053e202c1Schristos 		CMPOP("LGreater", >);
198153e202c1Schristos 		break;
198253e202c1Schristos 	case 0x95:
198353e202c1Schristos 		CMPOP("LLess", <);
198453e202c1Schristos 		break;
198553e202c1Schristos 	case 0xa0:		/* IfOp */
198653e202c1Schristos 		aname = aml_parse_defif(env, indent);
198753e202c1Schristos 		break;
198853e202c1Schristos #if 0
198953e202c1Schristos 
199053e202c1Schristos 	case 0xa1:		/* ElseOp should not be treated in Main parser
199153e202c1Schristos 				 * But If Op */
199253e202c1Schristos 		aml_parse_defelse(env, indent);
199353e202c1Schristos 		break;
199453e202c1Schristos #endif
199553e202c1Schristos 	case 0xa2:		/* WhileOp */
199653e202c1Schristos 		aname = aml_parse_defwhile(env, indent);
199753e202c1Schristos 		break;
199853e202c1Schristos 	case 0xa3:		/* NoopOp */
199953e202c1Schristos 		AML_DEBUGPRINT("Noop");
200053e202c1Schristos 		break;
200153e202c1Schristos 	case 0xa5:		/* BreakOp */
200253e202c1Schristos 		AML_DEBUGPRINT("Break");
200353e202c1Schristos 		env->stat = aml_stat_break;
200453e202c1Schristos 		break;
200553e202c1Schristos 	case 0xa4:		/* ReturnOp */
200653e202c1Schristos 		AML_DEBUGPRINT("Return(");
200753e202c1Schristos 		AML_COPY_OBJECT(env->tempname.property, env, aml_eval_name(env,
200853e202c1Schristos 		    aml_parse_termobj(env, indent)), NULL);
200953e202c1Schristos 		aname = &env->tempname;
201053e202c1Schristos 		env->stat = aml_stat_return;
201153e202c1Schristos 		AML_DEBUGPRINT(")");
201253e202c1Schristos 		break;
201353e202c1Schristos 	case 0xcc:		/* BreakPointOp */
201453e202c1Schristos 		/* XXX Not Yet Impremented (Not need?) */
201553e202c1Schristos 		AML_DEBUGPRINT("BreakPoint");
201653e202c1Schristos 		break;
201753e202c1Schristos 	default:
201853e202c1Schristos 		AML_SYSERRX(1, "strange opcode 0x%x\n", opcode);
201953e202c1Schristos 		AML_SYSABORT();
202053e202c1Schristos 	}
202153e202c1Schristos 
202253e202c1Schristos 	return (aname);
202353e202c1Schristos }
2024