4 * Copyright (c) 1999 Doug Rabson
5 * Copyright (c) 1999, 2000 Mitsuru IWASAKI <iwasaki@FreeBSD.org>
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
18 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
21 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29 * Id: aml_parse.c,v 1.32 2000/08/12 15:20:45 iwasaki Exp
30 * $FreeBSD: src/usr.sbin/acpi/amldb/aml/aml_parse.c,v 1.7 2001/10/23 14:54:15 takawata Exp $
32 #include <sys/cdefs.h>
35 #include <sys/param.h>
37 #include <acpi_common.h>
38 #include <aml/aml_amlmem.h>
39 #include <aml/aml_common.h>
40 #include <aml/aml_env.h>
41 #include <aml/aml_evalobj.h>
42 #include <aml/aml_name.h>
43 #include <aml/aml_obj.h>
44 #include <aml/aml_parse.h>
45 #include <aml/aml_status.h>
46 #include <aml/aml_store.h>
62 #include <sys/systm.h>
64 #include <machine/bus.h>
65 #include <dev/acpi/acpireg.h>
66 #include <dev/acpi/acpivar.h>
67 #ifndef ACPI_NO_OSDFUNC_INLINE
68 #include <machine/acpica_osd.h>
72 static int findsetleftbit(int num
);
73 static int findsetrightbit(int num
);
74 static int frombcd(int num
);
75 static int tobcd(int num
);
77 static u_int32_t
aml_parse_pkglength(struct aml_environ
*env
);
78 static u_int8_t
aml_parse_bytedata(struct aml_environ
*env
);
79 static u_int16_t
aml_parse_worddata(struct aml_environ
*env
);
80 static u_int32_t
aml_parse_dworddata(struct aml_environ
*env
);
81 static u_int8_t
*aml_parse_namestring(struct aml_environ
*env
);
82 static void aml_parse_defscope(struct aml_environ
*env
,
84 static union aml_object
*aml_parse_defbuffer(struct aml_environ
*env
,
86 static struct aml_name
*aml_parse_concat_number(struct aml_environ
*env
,
87 int num1
, int indent
);
88 static struct aml_name
*aml_parse_concat_buffer(struct aml_environ
*env
,
89 union aml_object
*obj
,
91 static struct aml_name
*aml_parse_concat_string(struct aml_environ
*env
,
92 union aml_object
*obj
,
94 static struct aml_name
*aml_parse_concatop(struct aml_environ
*env
,
96 static union aml_object
*aml_parse_defpackage(struct aml_environ
*env
,
98 static void aml_parse_defmethod(struct aml_environ
*env
,
100 static void aml_parse_defopregion(struct aml_environ
*env
,
102 static int aml_parse_field(struct aml_environ
*env
,
103 struct aml_field
*template);
104 static void aml_parse_fieldlist(struct aml_environ
*env
,
105 struct aml_field
*template,
107 static void aml_parse_deffield(struct aml_environ
*env
,
109 static void aml_parse_defindexfield(struct aml_environ
*env
,
111 static void aml_parse_defbankfield(struct aml_environ
*env
,
113 static void aml_parse_defdevice(struct aml_environ
*env
,
115 static void aml_parse_defprocessor(struct aml_environ
*env
,
117 static void aml_parse_defpowerres(struct aml_environ
*env
,
119 static void aml_parse_defthermalzone(struct aml_environ
*env
,
121 static struct aml_name
*aml_parse_defelse(struct aml_environ
*env
,
122 int indent
, int num
);
123 static struct aml_name
*aml_parse_defif(struct aml_environ
*env
,
125 static struct aml_name
*aml_parse_defwhile(struct aml_environ
*env
,
127 static void aml_parse_defmutex(struct aml_environ
*env
,
129 static void aml_createfield_generic(struct aml_environ
*env
,
130 union aml_object
*srcbuf
,
133 static void aml_parse_defcreatefield(struct aml_environ
*env
,
137 findsetleftbit(int num
)
142 for (i
= 0; i
< 32; i
++) {
143 filter
= filter
>> 1;
149 i
= (i
== 32) ? 0 : i
+ 1;
154 findsetrightbit(int num
)
159 for (i
= 0; i
< 32; i
++) {
160 filter
= filter
<< 1;
166 i
= (i
== 32) ? 0 : i
+ 1;
178 res
+= ((num
& 0xf) * factor
);
193 res
+= ((num
% 10) * factor
);
201 aml_parse_pkglength(struct aml_environ
*env
)
208 switch (pkglength
>> 6) {
212 pkglength
= (pkglength
& 0xf) + (dp
[0] << 4);
216 pkglength
= (pkglength
& 0xf) + (dp
[0] << 4) + (dp
[1] << 12);
220 pkglength
= (pkglength
& 0xf)
221 + (dp
[0] << 4) + (dp
[1] << 12) + (dp
[2] << 20);
231 aml_parse_bytedata(struct aml_environ
*env
)
241 aml_parse_worddata(struct aml_environ
*env
)
245 data
= env
->dp
[0] + (env
->dp
[1] << 8);
251 aml_parse_dworddata(struct aml_environ
*env
)
255 data
= env
->dp
[0] + (env
->dp
[1] << 8) +
256 (env
->dp
[2] << 16) + (env
->dp
[3] << 24);
262 aml_parse_namestring(struct aml_environ
*env
)
268 if (env
->dp
[0] == '\\')
270 else if (env
->dp
[0] == '^')
271 while (env
->dp
[0] == '^')
273 if (env
->dp
[0] == 0x00) /* NullName */
275 else if (env
->dp
[0] == 0x2e) /* DualNamePrefix */
276 env
->dp
+= 1 + 4 + 4; /* NameSeg, NameSeg */
277 else if (env
->dp
[0] == 0x2f) { /* MultiNamePrefix */
278 segcount
= env
->dp
[1];
279 env
->dp
+= 1 + 1 + segcount
* 4; /* segcount * NameSeg */
281 env
->dp
+= 4; /* NameSeg */
287 aml_parse_objectlist(struct aml_environ
*env
, int indent
)
289 union aml_object
*obj
;
292 while (env
->dp
< env
->end
) {
293 aml_print_indent(indent
);
294 obj
= aml_eval_name(env
, aml_parse_termobj(env
, indent
));
295 AML_DEBUGPRINT("\n");
296 if (env
->stat
== aml_stat_step
) {
297 AML_DEBUGGER(env
, env
);
300 if (env
->stat
!= aml_stat_none
) {
301 env
->tempname
.property
= obj
;
302 return (&env
->tempname
);
308 #define AML_CREATE_NAME(amlname, env, namestr, ret) do { \
309 amlname = aml_create_name(env, namestr); \
310 if (env->stat == aml_stat_panic) \
314 #define AML_COPY_OBJECT(dest, env, src, ret) do { \
315 dest = aml_copy_object(env, src); \
316 if (dest == NULL) { \
317 env->stat = aml_stat_panic; \
322 #define AML_ALLOC_OBJECT(dest, env, type, ret) do { \
323 dest = aml_alloc_object(type, NULL); \
324 if (dest == NULL) { \
325 env->stat= aml_stat_panic; \
331 aml_parse_defscope(struct aml_environ
*env
, int indent
)
333 u_int8_t
*start
, *end
, *oend
;
336 struct aml_name
*oname
;
339 pkglength
= aml_parse_pkglength(env
);
341 AML_DEBUGPRINT("Scope(");
342 name
= aml_parse_namestring(env
);
343 aml_print_namestring(name
);
344 AML_DEBUGPRINT(") {\n");
345 oname
= env
->curname
;
346 AML_CREATE_NAME(env
->curname
, env
, name
,);
348 env
->end
= end
= start
+ pkglength
;
349 aml_parse_objectlist(env
, indent
+ 1);
350 aml_print_indent(indent
);
352 AML_SYSASSERT(env
->dp
== env
->end
);
355 env
->curname
= oname
;
356 env
->stat
= aml_stat_none
;
359 static union aml_object
*
360 aml_parse_defbuffer(struct aml_environ
*env
, int indent
)
366 int size1
, size2
, size
;
367 union aml_object
*obj
;
370 pkglength
= aml_parse_pkglength(env
);
371 end
= start
+ pkglength
;
373 AML_DEBUGPRINT("Buffer(");
374 obj
= aml_eval_name(env
, aml_parse_termobj(env
, indent
));
375 size1
= aml_objtonum(env
, obj
);
376 size2
= end
- env
->dp
;
377 size
= (size1
< size2
) ? size1
: size2
;
379 buffer
= memman_alloc_flexsize(aml_memman
, size1
);
380 if (buffer
== NULL
) {
381 AML_DEBUGPRINT("NO MEMORY\n");
382 env
->stat
= aml_stat_panic
;
385 bzero(buffer
, size1
);
386 bcopy(env
->dp
, buffer
, size
);
391 obj
= &env
->tempobject
;
392 obj
->type
= aml_t_buffer
;
393 obj
->buffer
.size
= size1
;
394 obj
->buffer
.data
= buffer
;
395 AML_DEBUGPRINT(") ");
401 static struct aml_name
*
402 aml_parse_concat_number(struct aml_environ
*env
, int num1
, int indent
)
405 struct aml_name
*destname
;
406 union aml_object
*obj
;
408 num2
= aml_objtonum(env
, aml_eval_name(env
,
409 aml_parse_termobj(env
, indent
)));
410 AML_DEBUGPRINT(", ");
411 destname
= aml_parse_termobj(env
, indent
);
413 obj
= &env
->tempobject
;
414 obj
->type
= aml_t_buffer
;
415 obj
->buffer
.size
= 2;
416 obj
->buffer
.data
= memman_alloc_flexsize(aml_memman
, 2);
417 if (obj
->buffer
.data
== NULL
) {
418 env
->stat
= aml_stat_panic
;
421 obj
->buffer
.data
[0] = num1
& 0xff;
422 obj
->buffer
.data
[1] = num2
& 0xff;
423 aml_store_to_name(env
, obj
, destname
);
424 return (&env
->tempname
);
427 static struct aml_name
*
428 aml_parse_concat_buffer(struct aml_environ
*env
, union aml_object
*obj
,
431 union aml_object
*tmpobj
, *tmpobj2
, *resobj
;
432 struct aml_name
*destname
;
434 tmpobj
= aml_eval_name(env
, aml_parse_termobj(env
, indent
));
435 AML_DEBUGPRINT(", ");
436 if (tmpobj
->type
!= aml_t_buffer
) {
437 env
->stat
= aml_stat_panic
;
440 AML_COPY_OBJECT(tmpobj2
, env
, tmpobj
, NULL
);
441 destname
= aml_parse_termobj(env
, indent
);
443 resobj
= &env
->tempobject
;
444 env
->tempname
.property
= resobj
;
445 resobj
->buffer
.type
= aml_t_buffer
;
446 resobj
->buffer
.size
= tmpobj2
->buffer
.size
+ obj
->buffer
.size
;
447 if (resobj
->buffer
.size
> 0) {
448 resobj
->buffer
.data
= memman_alloc_flexsize(aml_memman
,
449 resobj
->buffer
.size
);
450 if (resobj
->buffer
.data
== NULL
) {
451 env
->stat
= aml_stat_panic
;
454 bcopy(obj
->buffer
.data
, resobj
->buffer
.data
, obj
->buffer
.size
);
455 bcopy(tmpobj2
->buffer
.data
,
456 resobj
->buffer
.data
+ obj
->buffer
.size
,
457 tmpobj2
->buffer
.size
);
459 resobj
->buffer
.data
= NULL
;
461 aml_free_object(&tmpobj2
);
462 aml_store_to_name(env
, resobj
, destname
);
463 return (&env
->tempname
);
466 static struct aml_name
*
467 aml_parse_concat_string(struct aml_environ
*env
, union aml_object
*obj
,
471 union aml_object
*tmpobj
, *tmpobj2
, *resobj
;
472 struct aml_name
*destname
;
474 tmpobj
= aml_eval_name(env
, aml_parse_termobj(env
, indent
));
475 AML_DEBUGPRINT(", ");
476 if (tmpobj
->type
!= aml_t_string
) {
477 env
->stat
= aml_stat_panic
;
480 AML_COPY_OBJECT(tmpobj2
, env
, tmpobj
, NULL
);
481 destname
= aml_parse_termobj(env
, indent
);
483 resobj
= &env
->tempobject
;
484 env
->tempname
.property
= resobj
;
485 resobj
->type
= aml_t_buffer
;
486 resobj
->str
.needfree
= 1;
487 len
= strlen((const char *)obj
->str
.string
) +
488 strlen((const char *)tmpobj2
->str
.string
) + 1;
490 resobj
->str
.string
= memman_alloc_flexsize(aml_memman
, len
);
491 if (resobj
->str
.string
== NULL
) {
492 env
->stat
= aml_stat_panic
;
495 strlcpy((char *)resobj
->str
.string
, (const char *)obj
->str
.string
, len
);
496 strlcat((char *)resobj
->str
.string
, (const char *)tmpobj
->str
.string
, len
);
498 resobj
->str
.string
= NULL
;
500 aml_free_object(&tmpobj2
);
501 aml_store_to_name(env
, resobj
, destname
);
502 return (&env
->tempname
);
505 static struct aml_name
*
506 aml_parse_concatop(struct aml_environ
*env
, int indent
)
508 union aml_object
*obj
, *tmpobj
;
509 struct aml_name
*aname
;
511 AML_DEBUGPRINT("Concat(");
512 obj
= aml_eval_name(env
, aml_parse_termobj(env
, indent
));
513 AML_DEBUGPRINT(", ");
516 aname
= aml_parse_concat_number(env
, aml_objtonum(env
, obj
), indent
);
520 /* obj may be temporal object */
521 AML_COPY_OBJECT(tmpobj
, env
, obj
, NULL
);
522 aname
= aml_parse_concat_buffer(env
, obj
, indent
);
523 aml_free_object(&tmpobj
);
527 /* obj may be temporal object */
528 AML_COPY_OBJECT(tmpobj
, env
, obj
, NULL
);
529 aname
= aml_parse_concat_string(env
, obj
, indent
);
530 aml_free_object(&tmpobj
);
534 env
->stat
= aml_stat_panic
;
539 AML_DEBUGPRINT("\n");
543 static union aml_object
*
544 aml_parse_defpackage(struct aml_environ
*env
, int indent
)
546 u_int8_t numelements
;
550 struct aml_environ
*copy
;
551 struct aml_name
*tmpname
;
552 union aml_object
*obj
, **objects
;
555 pkglength
= aml_parse_pkglength(env
);
556 numelements
= aml_parse_bytedata(env
);
557 copy
= memman_alloc(aml_memman
, memid_aml_environ
);
559 env
->stat
= aml_stat_panic
;
562 if (numelements
> 0) {
563 objects
= memman_alloc_flexsize(aml_memman
,
564 numelements
* sizeof(union aml_object
*));
565 if (objects
== NULL
) {
566 env
->stat
= aml_stat_panic
;
569 bzero(objects
, numelements
* sizeof(union aml_object
*));
576 env
->dp
= copy
->end
= start
+ pkglength
;
577 AML_DEBUGPRINT("Package() {\n");
579 while ((copy
->dp
< copy
->end
) && (i
< numelements
)) {
580 aml_print_indent(indent
+ 1);
581 tmpname
= aml_parse_termobj(copy
, indent
+ 1);
583 if (tmpname
!= NULL
) {
584 objects
[i
] = aml_copy_object(copy
, tmpname
->property
);
586 AML_DEBUGPRINT(",\n");
589 aml_free_objectcontent(©
->tempobject
);
591 aml_print_indent(indent
);
593 obj
= &env
->tempobject
;
594 obj
->type
= aml_t_package
;
595 obj
->package
.elements
= numelements
;
596 obj
->package
.objects
= objects
;
598 memman_free(aml_memman
, memid_aml_environ
, copy
);
603 aml_parse_defmethod(struct aml_environ
*env
, int indent
)
609 struct aml_environ
*copy
;
610 struct aml_method
*meth
;
611 struct aml_name
*aname
;
612 union aml_object
*aobj
;
615 pkglength
= aml_parse_pkglength(env
);
616 copy
= memman_alloc(aml_memman
, memid_aml_environ
);
618 env
->stat
= aml_stat_panic
;
621 AML_DEBUGPRINT("Method(");
622 name
= (char *)aml_parse_namestring(env
);
623 aml_print_namestring((unsigned char *)name
);
624 AML_CREATE_NAME(aname
, env
, (unsigned char *)name
,);
625 if (aname
->property
!= NULL
) {
626 env
->stat
= aml_stat_panic
;
627 AML_DEBUGPRINT("Already Defined \n");
630 AML_ALLOC_OBJECT(aobj
, env
, aml_t_method
,);
632 aname
->property
= aobj
;
636 AML_DEBUGPRINT(", %d", flags
);
638 AML_DEBUGPRINT(") {\n");
640 meth
->argnum
= flags
;
641 meth
->from
= env
->dp
;
642 meth
->to
= env
->dp
= copy
->end
= start
+ pkglength
;
643 aml_print_indent(indent
);
646 memman_free(aml_memman
, memid_aml_environ
, copy
);
650 aml_parse_defopregion(struct aml_environ
*env
, int indent
)
653 struct aml_name
*aname
;
654 struct aml_opregion
*opregion
;
655 union aml_object
*obj
;
656 const char *regions
[] = {
664 AML_DEBUGPRINT("OperationRegion(");
666 name
= aml_parse_namestring(env
);
667 aml_print_namestring(name
);
668 AML_CREATE_NAME(aname
, env
, name
,);
669 if (aname
->property
!= NULL
) {
670 env
->stat
= aml_stat_panic
;
671 AML_DEBUGPRINT("Already Defined \n");
674 AML_ALLOC_OBJECT(aname
->property
, env
, aml_t_opregion
,);
675 opregion
= &aname
->property
->opregion
;
676 opregion
->space
= *env
->dp
;
677 AML_DEBUGPRINT(", %s, ", regions
[*env
->dp
]); /* Space */
679 obj
= aml_eval_name(env
, aml_parse_termobj(env
, indent
)); /* Offset */
680 opregion
->offset
= aml_objtonum(env
, obj
);
681 AML_DEBUGPRINT(", ");
682 obj
= aml_eval_name(env
, aml_parse_termobj(env
, indent
)); /* Length */
683 opregion
->length
= aml_objtonum(env
, obj
);
687 static const char *accessnames
[] = {
698 aml_parse_field(struct aml_environ
*env
, struct aml_field
*template)
701 u_int8_t acc
, attribute
;
703 struct aml_name
*aname
;
704 struct aml_field
*prop
;
713 name
= aml_parse_namestring(env
);
714 width
= aml_parse_pkglength(env
);
715 template->bitlen
= width
;
716 aml_print_namestring(name
);
717 AML_CREATE_NAME(aname
, env
, name
, 0);
720 template->bitoffset
+= 15;
721 template->bitoffset
&= (~15);
724 template->bitoffset
+= 31;
725 template->bitoffset
&= (~31);
726 } else if ((width
& 7) == 0) {
727 template->bitoffset
+= 7;
728 template->bitoffset
&= (~7);
729 } else if ((width
> 32) && (width
& 7) != 0) {
730 AML_DEBUGPRINT("??? Can I treat it?\n");
732 if (aname
->property
!= NULL
) {
733 env
->stat
= aml_stat_panic
;
734 AML_DEBUGPRINT("Already Defined \n");
737 AML_ALLOC_OBJECT(aname
->property
, env
, aml_t_field
, 0);
738 prop
= &aname
->property
->field
;
740 template->bitoffset
+= width
;
741 AML_DEBUGPRINT(",\t%d", width
);
745 width
= aml_parse_pkglength(env
);
746 template->bitoffset
+= width
;
747 AML_DEBUGPRINT("Offset(0x%x)", template->bitoffset
);
751 attribute
= env
->dp
[2];
753 AML_DEBUGPRINT("AccessAs(%s, %d)", accessnames
[acc
], attribute
);
754 template->bitoffset
= attribute
;
755 template->flags
= (template->flags
| 0xf0) | acc
;
758 return (template->bitoffset
);
762 aml_parse_fieldlist(struct aml_environ
*env
, struct aml_field
*template,
768 while (env
->dp
< env
->end
) {
769 aml_print_indent(indent
);
770 offset
= aml_parse_field(env
, template);
771 if (env
->dp
< env
->end
) {
772 AML_DEBUGPRINT(",\n");
774 AML_DEBUGPRINT("\n");
780 aml_parse_deffield(struct aml_environ
*env
, int indent
)
783 u_int8_t
*start
, *name
;
785 struct aml_environ
*copy
;
786 struct aml_field fieldtemplate
;
787 static const char *lockrules
[] = {"NoLock", "Lock"};
788 static const char *updaterules
[] = {"Preserve", "WriteAsOnes",
789 "WriteAsZeros", "*Error*"};
792 pkglength
= aml_parse_pkglength(env
);
793 copy
= memman_alloc(aml_memman
, memid_aml_environ
);
795 env
->stat
= aml_stat_panic
;
798 AML_DEBUGPRINT("Field(");
799 aml_print_namestring(name
= aml_parse_namestring(env
));
800 fieldtemplate
.type
= aml_t_field
;
801 flags
= aml_parse_bytedata(env
);
802 fieldtemplate
.flags
= fieldtemplate
.flags
= flags
;
805 env
->dp
= copy
->end
= start
+ pkglength
;
806 fieldtemplate
.bitoffset
= 0;
807 fieldtemplate
.bitlen
= 0;
808 fieldtemplate
.f
.ftype
= f_t_field
;
809 fieldtemplate
.f
.fld
.regname
= name
;
810 AML_DEBUGPRINT(", %s, %s, %s) {\n",
811 accessnames
[flags
& 0xf],
812 lockrules
[(flags
>> 4) & 1],
813 updaterules
[(flags
>> 5) & 3]);
814 aml_parse_fieldlist(copy
, &fieldtemplate
, indent
+ 1);
815 aml_print_indent(indent
);
817 aml_free_objectcontent(©
->tempobject
);
819 AML_SYSASSERT(copy
->dp
== copy
->end
);
820 memman_free(aml_memman
, memid_aml_environ
, copy
);
824 aml_parse_defindexfield(struct aml_environ
*env
, int indent
)
827 u_int8_t
*start
, *iname
, *dname
;
829 struct aml_environ
*copy
;
830 struct aml_field
template;
831 static const char *lockrules
[] = {"NoLock", "Lock"};
832 static const char *updaterules
[] = {"Preserve", "WriteAsOnes",
833 "WriteAsZeros", "*Error*"};
836 pkglength
= aml_parse_pkglength(env
);
837 copy
= memman_alloc(aml_memman
, memid_aml_environ
);
839 env
->stat
= aml_stat_panic
;
842 AML_DEBUGPRINT("IndexField(");
843 aml_print_namestring(iname
= aml_parse_namestring(env
)); /* Name1 */
844 AML_DEBUGPRINT(", ");
845 aml_print_namestring(dname
= aml_parse_namestring(env
)); /* Name2 */
846 template.type
= aml_t_field
;
847 template.flags
= flags
= aml_parse_bytedata(env
);
848 template.bitoffset
= 0;
850 template.f
.ftype
= f_t_index
;
851 template.f
.ifld
.indexname
= iname
;
852 template.f
.ifld
.dataname
= dname
;
853 AML_DEBUGPRINT(", %s, %s, %s) {\n",
854 accessnames
[flags
& 0xf],
855 lockrules
[(flags
>> 4) & 1],
856 updaterules
[(flags
>> 5) & 3]);
858 env
->dp
= copy
->end
= start
+ pkglength
;
859 aml_parse_fieldlist(copy
, &template, indent
+ 1);
860 aml_print_indent(indent
);
862 aml_free_objectcontent(©
->tempobject
);
864 AML_SYSASSERT(copy
->dp
== copy
->end
);
865 memman_free(aml_memman
, memid_aml_environ
, copy
);
869 aml_parse_defbankfield(struct aml_environ
*env
, int indent
)
872 u_int8_t
*start
, *rname
, *bname
;
873 u_int32_t pkglength
, bankvalue
;
874 struct aml_environ
*copy
;
875 struct aml_field
template;
876 union aml_object
*obj
;
877 static const char *lockrules
[] = {"NoLock", "Lock"};
878 static const char *updaterules
[] = {"Preserve", "WriteAsOnes",
879 "WriteAsZeros", "*Error*"};
882 pkglength
= aml_parse_pkglength(env
);
883 copy
= memman_alloc(aml_memman
, memid_aml_environ
);
885 env
->stat
= aml_stat_panic
;
888 AML_DEBUGPRINT("BankField(");
889 aml_print_namestring(rname
= aml_parse_namestring(env
)); /* Name1 */
890 AML_DEBUGPRINT(", ");
891 aml_print_namestring(bname
= aml_parse_namestring(env
)); /* Name2 */
892 AML_DEBUGPRINT(", ");
893 obj
= aml_eval_name(env
, aml_parse_termobj(env
, indent
)); /* BankValue */
894 bankvalue
= aml_objtonum(env
, obj
);
895 template.type
= aml_t_field
;
896 template.flags
= flags
= aml_parse_bytedata(env
);
897 template.bitoffset
= 0;
899 template.f
.ftype
= f_t_bank
;
900 template.f
.bfld
.regname
= rname
;
901 template.f
.bfld
.bankname
= bname
;
902 template.f
.bfld
.bankvalue
= bankvalue
;
904 env
->dp
= copy
->end
= start
+ pkglength
;
905 AML_DEBUGPRINT(", %s, %s, %s) {\n",
906 accessnames
[flags
& 0xf],
907 lockrules
[(flags
>> 4) & 1],
908 updaterules
[(flags
>> 5) & 3]);
909 aml_parse_fieldlist(copy
, &template, indent
+ 1);
910 aml_print_indent(indent
);
913 aml_free_objectcontent(©
->tempobject
);
914 AML_SYSASSERT(copy
->dp
== copy
->end
);
915 memman_free(aml_memman
, memid_aml_environ
, copy
);
919 aml_parse_defdevice(struct aml_environ
*env
, int indent
)
924 struct aml_environ
*copy
;
927 pkglength
= aml_parse_pkglength(env
);
928 copy
= memman_alloc(aml_memman
, memid_aml_environ
);
930 env
->stat
= aml_stat_panic
;
933 AML_DEBUGPRINT("Device(");
934 name
= aml_parse_namestring(env
);
935 aml_print_namestring(name
);
936 AML_DEBUGPRINT(") {\n");
938 AML_CREATE_NAME(copy
->curname
, env
, name
,);
939 if (copy
->curname
->property
!= NULL
) {
940 env
->stat
= aml_stat_panic
;
941 AML_DEBUGPRINT("Already Defined \n");
944 AML_ALLOC_OBJECT(copy
->curname
->property
, env
, aml_t_device
,);
945 env
->dp
= copy
->end
= start
+ pkglength
;
946 aml_parse_objectlist(copy
, indent
+ 1);
947 aml_print_indent(indent
);
949 aml_free_objectcontent(©
->tempobject
);
951 AML_SYSASSERT(copy
->dp
== copy
->end
);
953 memman_free(aml_memman
, memid_aml_environ
, copy
);
957 aml_parse_defprocessor(struct aml_environ
*env
, int indent
)
962 struct aml_environ
*copy
;
963 struct aml_processor
*proc
;
964 union aml_object
*obj
;
967 pkglength
= aml_parse_pkglength(env
);
968 copy
= memman_alloc(aml_memman
, memid_aml_environ
);
970 env
->stat
= aml_stat_panic
;
973 AML_ALLOC_OBJECT(obj
, env
, aml_t_processor
,);
975 AML_DEBUGPRINT("Processor(");
976 name
= aml_parse_namestring(env
);
977 aml_print_namestring(name
);
978 proc
->id
= aml_parse_bytedata(env
);
979 proc
->addr
= aml_parse_dworddata(env
);
980 proc
->len
= aml_parse_bytedata(env
);
981 AML_DEBUGPRINT(", %d, 0x%x, 0x%x) {\n", proc
->id
, proc
->addr
, proc
->len
);
983 AML_CREATE_NAME(copy
->curname
, env
, name
,);
984 if (copy
->curname
->property
!= NULL
) {
985 env
->stat
= aml_stat_panic
;
986 AML_DEBUGPRINT("Already Defined \n");
989 copy
->curname
->property
= obj
;
990 env
->dp
= copy
->end
= start
+ pkglength
;
991 aml_parse_objectlist(copy
, indent
+ 1);
992 aml_print_indent(indent
);
994 aml_free_objectcontent(©
->tempobject
);
996 AML_SYSASSERT(copy
->dp
== copy
->end
);
998 memman_free(aml_memman
, memid_aml_environ
, copy
);
1002 aml_parse_defpowerres(struct aml_environ
*env
, int indent
)
1006 u_int32_t pkglength
;
1007 struct aml_environ
*copy
;
1008 struct aml_powerres
*pres
;
1009 union aml_object
*obj
;
1012 pkglength
= aml_parse_pkglength(env
);
1013 copy
= memman_alloc(aml_memman
, memid_aml_environ
);
1015 env
->stat
= aml_stat_panic
;
1018 AML_DEBUGPRINT("PowerResource(");
1019 AML_ALLOC_OBJECT(obj
, env
, aml_t_powerres
,);
1020 name
= aml_parse_namestring(env
);
1021 aml_print_namestring(name
);
1023 pres
->level
= aml_parse_bytedata(env
);
1024 pres
->order
= aml_parse_worddata(env
);
1025 AML_DEBUGPRINT(", %d, %d) {\n", pres
->level
, pres
->order
);
1027 AML_CREATE_NAME(copy
->curname
, env
, name
,);
1028 if (copy
->curname
->property
!= NULL
) {
1029 env
->stat
= aml_stat_panic
;
1030 AML_DEBUGPRINT("Already Defined \n");
1033 copy
->curname
->property
= obj
;
1034 env
->dp
= copy
->end
= start
+ pkglength
;
1036 aml_parse_objectlist(copy
, indent
+ 1);
1037 aml_print_indent(indent
);
1038 AML_DEBUGPRINT("}");
1039 aml_free_objectcontent(©
->tempobject
);
1041 AML_SYSASSERT(copy
->dp
== copy
->end
);
1043 memman_free(aml_memman
, memid_aml_environ
, copy
);
1047 aml_parse_defthermalzone(struct aml_environ
*env
, int indent
)
1051 u_int32_t pkglength
;
1052 struct aml_environ
*copy
;
1055 pkglength
= aml_parse_pkglength(env
);
1056 copy
= memman_alloc(aml_memman
, memid_aml_environ
);
1058 env
->stat
= aml_stat_panic
;
1061 AML_DEBUGPRINT("ThermalZone(");
1062 name
= aml_parse_namestring(env
);
1063 aml_print_namestring(name
);
1064 AML_DEBUGPRINT(") {\n");
1066 AML_CREATE_NAME(copy
->curname
, env
, name
,);
1067 if (copy
->curname
->property
!= NULL
) {
1068 env
->stat
= aml_stat_panic
;
1069 AML_DEBUGPRINT("Already Defined \n");
1072 AML_ALLOC_OBJECT(copy
->curname
->property
, env
, aml_t_therm
,);
1073 env
->dp
= copy
->end
= start
+ pkglength
;
1074 aml_parse_objectlist(copy
, indent
+ 1);
1075 aml_print_indent(indent
);
1076 AML_DEBUGPRINT("}");
1077 aml_free_objectcontent(©
->tempobject
);
1078 AML_SYSASSERT(copy
->dp
== copy
->end
);
1080 memman_free(aml_memman
, memid_aml_environ
, copy
);
1083 static struct aml_name
*
1084 aml_parse_defelse(struct aml_environ
*env
, int indent
, int num
)
1086 u_int8_t
*start
, *end
, *oend
;
1087 u_int32_t pkglength
;
1088 struct aml_name
*aname
;
1091 pkglength
= aml_parse_pkglength(env
);
1093 env
->end
= end
= start
+ pkglength
;
1096 AML_DEBUGPRINT("Else {\n");
1098 aname
= aml_parse_objectlist(env
, indent
+ 1);
1099 aml_print_indent(indent
);
1101 AML_DEBUGPRINT("}");
1108 static struct aml_name
*
1109 aml_parse_defif(struct aml_environ
*env
, int indent
)
1111 u_int8_t
*start
, *end
, *oend
;
1112 u_int32_t pkglength
;
1114 struct aml_name
*aname
, *aname1
;
1117 pkglength
= aml_parse_pkglength(env
);
1120 AML_DEBUGPRINT("If(");
1121 num
= aml_objtonum(env
, aml_eval_name
1122 (env
, aml_parse_termobj(env
, indent
)));
1124 end
= start
+ pkglength
;
1125 AML_DEBUGPRINT(")");
1127 AML_DEBUGPRINT("{\n");
1129 aname
= aml_parse_objectlist(env
, indent
+ 1);
1130 aml_print_indent(indent
);
1131 AML_DEBUGPRINT("}");
1135 if ((end
< oend
) && *(env
->dp
) == 0xa1) {
1137 aname1
= aml_parse_defelse(env
, indent
, num
);
1138 aname
= (num
== 0) ? aname1
: aname
;
1143 static struct aml_name
*
1144 aml_parse_defwhile(struct aml_environ
*env
, int indent
)
1146 u_int8_t
*start
, *end
, *oend
;
1147 u_int32_t pkglength
;
1149 struct aml_name
*aname
;
1152 pkglength
= aml_parse_pkglength(env
);
1154 end
= start
+ pkglength
;
1158 aml_parse_pkglength(env
);
1159 AML_DEBUGPRINT("While(");
1160 num
= aml_objtonum(env
, aml_eval_name
1161 (env
, aml_parse_termobj(env
, indent
)));
1162 AML_DEBUGPRINT(")");
1166 AML_DEBUGPRINT(" {\n");
1168 aname
= aml_parse_objectlist(env
, indent
+ 1);
1169 if (env
->stat
== aml_stat_step
) {
1170 AML_DEBUGGER(env
, env
);
1173 if (env
->stat
!= aml_stat_none
)
1175 aml_print_indent(indent
);
1176 AML_DEBUGPRINT("}");
1178 AML_DEBUGPRINT("\n");
1181 if (env
->stat
== aml_stat_break
) {
1182 env
->stat
= aml_stat_none
;
1189 aml_parse_defmutex(struct aml_environ
*env
, int indent
)
1192 struct aml_name
*aname
;
1193 struct aml_mutex
*mut
;
1196 AML_DEBUGPRINT("Mutex(");
1197 name
= (char *)aml_parse_namestring(env
);
1198 aml_print_namestring((unsigned char *)name
);
1199 AML_CREATE_NAME(aname
, env
, (unsigned char *)name
,);
1200 if (aname
->property
!= NULL
) {
1201 env
->stat
= aml_stat_panic
;
1202 AML_DEBUGPRINT("Already Defined \n");
1205 AML_ALLOC_OBJECT(aname
->property
, env
, aml_t_mutex
,);
1206 mut
= &aname
->property
->mutex
;
1207 mut
->level
= *env
->dp
++;
1208 STAILQ_INIT(&mut
->queue
);
1209 AML_DEBUGPRINT(", %d)", mut
->level
);
1213 aml_createfield_generic(struct aml_environ
*env
,
1214 union aml_object
*srcbuf
, int idx
,
1215 int len
, char *newname
)
1217 struct aml_bufferfield
*field
;
1218 struct aml_name
*aname
;
1220 if (srcbuf
== NULL
|| srcbuf
->type
!= aml_t_buffer
) {
1221 AML_DEBUGPRINT("Not Buffer assigned,");
1222 env
->stat
= aml_stat_panic
;
1225 AML_CREATE_NAME(aname
, env
, (unsigned char *)newname
,);
1226 if (aname
->property
!= NULL
) {
1227 env
->stat
= aml_stat_panic
;
1228 AML_DEBUGPRINT("Already Defined \n");
1231 AML_ALLOC_OBJECT(aname
->property
, env
, aml_t_bufferfield
,);
1232 field
= &aname
->property
->bfld
;
1233 field
->bitoffset
= idx
;
1234 field
->bitlen
= len
;
1235 field
->origin
= srcbuf
->buffer
.data
;
1239 aml_parse_defcreatefield(struct aml_environ
*env
, int indent
)
1243 union aml_object
*obj
, *srcbuf
;
1246 AML_DEBUGPRINT("CreateField(");
1247 srcbuf
= aml_eval_name(env
, aml_parse_termobj(env
, indent
));
1248 if (srcbuf
== &env
->tempobject
) {
1249 AML_DEBUGPRINT("NONAMED BUFFER\n");
1250 env
->stat
= aml_stat_panic
;
1253 AML_DEBUGPRINT(", ");
1254 obj
= aml_eval_name(env
, aml_parse_termobj(env
, indent
));
1255 idx
= aml_objtonum(env
, obj
);
1256 AML_DEBUGPRINT(", ");
1257 obj
= aml_eval_name(env
, aml_parse_termobj(env
, indent
));
1258 len
= aml_objtonum(env
, obj
);
1259 AML_DEBUGPRINT(", ");
1260 newname
= (char *)aml_parse_namestring(env
);
1261 aml_print_namestring((unsigned char *)newname
);
1262 aml_createfield_generic(env
, srcbuf
, idx
, len
, newname
);
1263 AML_DEBUGPRINT(") ");
1267 * Returns Named object or parser buffer. The object need not be free because
1268 * it returns preallocated buffer in env or Contain of named object. If You
1269 * need to preserve object, create a copy and then store. And The object
1270 * returned from this function is not valid after another call is
1271 * shared, tempolary buffer may be shared.
1274 aml_parse_termobj(struct aml_environ
*env
, int indent
)
1281 int match1
, match2
, i
, pkgval
, start
;
1282 int widthindex
, idx
;
1284 struct aml_name
*aname
;
1285 struct aml_name
*destname1
, *destname2
;
1286 struct aml_name
*tmpname
, *srcname
;
1287 struct aml_name
*src
;
1288 union aml_object
*ret
;
1289 union aml_object
*tmpobj
;
1290 union aml_object anum
;
1291 union aml_object
*objref
;
1292 union aml_object
*srcobj
;
1293 union aml_object
*obj
;
1294 union aml_object
*srcbuf
;
1295 static int widthtbl
[4] = {32, 16, 8, 1};
1296 const char *opname
[4] = {"CreateDWordField", "CreateWordField",
1297 "CreateByteField", "CreateBitField"};
1299 aname
= &env
->tempname
;
1300 ret
= &env
->tempobject
;
1301 anum
.type
= aml_t_num
;
1302 aname
->property
= ret
;
1303 aml_free_objectcontent(ret
);
1304 if (env
->stat
== aml_stat_panic
) {
1306 * If previosuly parser panic , parsing next instruction is
1312 opcode
= *env
->dp
++;
1321 ret
->type
= aml_t_namestr
;
1322 ret
->nstr
.dp
= aml_parse_namestring(env
);
1323 aml_print_namestring(ret
->nstr
.dp
);
1324 aname
= &env
->tempname
;
1326 case 0x0a: /* BytePrefix */
1327 ret
->type
= aml_t_num
;
1328 value
= aml_parse_bytedata(env
);
1329 ret
->num
.number
= value
;
1330 AML_DEBUGPRINT("0x%x", value
);
1331 aname
= &env
->tempname
;
1333 case 0x0b: /* WordPrefix */
1334 ret
->type
= aml_t_num
;
1335 value
= aml_parse_worddata(env
);
1336 ret
->num
.number
= value
;
1337 AML_DEBUGPRINT("0x%x", value
);
1338 aname
= &env
->tempname
;
1340 case 0x0c: /* DWordPrefix */
1341 ret
->type
= aml_t_num
;
1342 value
= aml_parse_dworddata(env
);
1343 ret
->num
.number
= value
;
1344 AML_DEBUGPRINT("0x%x", value
);
1345 aname
= &env
->tempname
;
1347 case 0x0d: /* StringPrefix */
1348 ret
->type
= aml_t_string
;
1349 ret
->str
.string
= env
->dp
;
1350 len
= strlen((const char *)env
->dp
);
1351 ret
->str
.needfree
= 0;
1352 AML_DEBUGPRINT("\"%s\"", (const char *)ret
->str
.string
);
1353 env
->dp
+= (len
+ 1);
1354 aname
= &env
->tempname
;
1356 case 0x00: /* ZeroOp */
1357 ret
->type
= aml_t_num
;
1358 ret
->num
.number
= 0;
1359 ret
->num
.constant
= 1;
1360 AML_DEBUGPRINT("Zero");
1361 aname
= &env
->tempname
;
1363 case 0x01: /* OneOp */
1364 ret
->type
= aml_t_num
;
1365 ret
->num
.number
= 1;
1366 ret
->num
.constant
= 1;
1367 AML_DEBUGPRINT("One");
1368 aname
= &env
->tempname
;
1370 case 0xff: /* OnesOp */
1371 ret
->type
= aml_t_num
;
1372 ret
->num
.number
= 0xffffffff;
1373 ret
->num
.constant
= 1;
1374 AML_DEBUGPRINT("Ones");
1375 aname
= &env
->tempname
;
1377 case 0x06: /* AliasOp */
1378 AML_DEBUGPRINT("Alias(");
1379 tmpname
= aml_parse_termobj(env
, indent
);
1380 if (env
->stat
== aml_stat_panic
) {
1383 if (tmpname
->property
== NULL
||
1384 tmpname
->property
->type
!= aml_t_namestr
) {
1385 env
->stat
= aml_stat_panic
;
1389 * XXX if srcname is deleted after this object, what
1392 srcname
= aml_search_name(env
, tmpname
->property
->nstr
.dp
);
1393 AML_DEBUGPRINT(", ");
1394 name
= aml_parse_namestring(env
);
1395 aml_print_namestring(name
);
1396 AML_CREATE_NAME(aname
, env
, name
, 0);
1397 if (aname
->property
!= NULL
) {
1398 env
->stat
= aml_stat_panic
;
1399 AML_DEBUGPRINT("Already Defined \n");
1400 aml_print_curname(aname
);
1403 AML_ALLOC_OBJECT(aname
->property
, env
, aml_t_objref
, NULL
);
1404 objref
= aname
->property
;
1405 objref
->objref
.nameref
= srcname
;
1406 objref
->objref
.ref
= srcname
->property
;
1407 objref
->objref
.offset
= -1;
1408 objref
->objref
.alias
= 1; /* Yes, this is an alias */
1409 AML_DEBUGPRINT(")");
1410 /* shut the interpreter up during the namespace initializing */
1412 case 0x08: /* NameOp */
1413 AML_DEBUGPRINT("Name(");
1414 name
= aml_parse_namestring(env
);
1415 aml_print_namestring(name
);
1416 AML_CREATE_NAME(aname
, env
, name
, 0);
1417 if (env
->stat
== aml_stat_panic
) {
1418 AML_DEBUGPRINT("Already Defined \n");
1419 aml_print_curname(aname
);
1422 AML_DEBUGPRINT(", ");
1423 AML_COPY_OBJECT(aname
->property
, env
,
1425 aml_parse_termobj(env
, indent
)),
1427 AML_DEBUGPRINT(")");
1429 case 0x10: /* ScopeOp */
1430 aml_parse_defscope(env
, indent
);
1432 case 0x11: /* BufferOp */
1433 aname
= &env
->tempname
;
1434 aname
->property
= aml_parse_defbuffer(env
, indent
);
1436 case 0x12: /* PackageOp */
1437 aname
= &env
->tempname
;
1438 aname
->property
= aml_parse_defpackage(env
, indent
);
1440 case 0x14: /* MethodOp */
1441 aml_parse_defmethod(env
, indent
);
1443 case 0x5b: /* ExtOpPrefix */
1444 opcode
= *env
->dp
++;
1447 aml_parse_defmutex(env
, indent
);
1449 case 0x02: /* EventOp */
1450 AML_DEBUGPRINT("Event(");
1451 name
= aml_parse_namestring(env
);
1452 aml_print_namestring(name
);
1453 AML_CREATE_NAME(aname
, env
, name
, 0);
1454 if (aname
->property
!= NULL
) {
1455 env
->stat
= aml_stat_panic
;
1456 AML_DEBUGPRINT("Already Defined \n");
1459 AML_ALLOC_OBJECT(aname
->property
, env
, aml_t_event
, NULL
);
1460 AML_DEBUGPRINT(")");
1463 case 0x12: /* CondRefOfOp */
1464 AML_DEBUGPRINT("CondRefOf(");
1465 src
= aml_parse_termobj(env
, indent
);
1466 AML_DEBUGPRINT(", ");
1467 if (src
== &env
->tempname
|| src
== NULL
) {
1468 aml_parse_termobj(env
, indent
);
1469 AML_DEBUGPRINT(")");
1470 anum
.num
.number
= 0xffffffff;
1471 env
->tempobject
.num
= anum
.num
;
1472 aname
= &env
->tempname
;
1475 AML_ALLOC_OBJECT(objref
, env
, aml_t_objref
, NULL
);
1476 if (src
->property
== NULL
||
1477 src
->property
->type
!= aml_t_namestr
) {
1478 objref
->objref
.nameref
= src
;
1480 objref
->objref
.nameref
= aml_create_local_object();
1482 objref
->objref
.ref
= src
->property
;
1483 objref
->objref
.offset
= -1; /* different from IndexOp */
1485 destname1
= aml_parse_termobj(env
, indent
);
1486 aml_store_to_name(env
, objref
, destname1
);
1487 anum
.num
.number
= 0;
1488 env
->tempobject
.num
= anum
.num
;
1489 aname
= &env
->tempname
;
1490 AML_DEBUGPRINT(")");
1493 aml_parse_defcreatefield(env
, indent
);
1495 case 0x20: /* LoadOp *//* XXX Not Impremented */
1496 AML_DEBUGPRINT("Load(");
1497 aml_parse_termobj(env
, indent
);
1498 AML_DEBUGPRINT(", ");
1499 aml_parse_termobj(env
, indent
);
1500 AML_DEBUGPRINT(")");
1502 case 0x21: /* StallOp */
1503 AML_DEBUGPRINT("Stall(");
1504 num1
= aml_objtonum(env
, aml_eval_name(env
,
1505 aml_parse_termobj(env
, indent
)));
1506 AML_DEBUGPRINT(")");
1509 case 0x22: /* SleepOp */
1510 AML_DEBUGPRINT("Sleep(");
1511 num1
= aml_objtonum(env
, aml_eval_name(env
,
1512 aml_parse_termobj(env
, indent
)));
1514 AML_DEBUGPRINT(")");
1516 case 0x23: /* AcquireOp *//* XXX Not yet */
1517 AML_DEBUGPRINT("Acquire(");
1518 aml_parse_termobj(env
, indent
);
1519 AML_DEBUGPRINT(", 0x%x)", aml_parse_worddata(env
));
1521 case 0x24: /* SignalOp *//* XXX Not yet */
1522 AML_DEBUGPRINT("Signal(");
1523 aml_parse_termobj(env
, indent
);
1524 AML_DEBUGPRINT(")");
1526 case 0x25: /* WaitOp *//* XXX Not yet impremented */
1527 AML_DEBUGPRINT("Wait(");
1528 aml_parse_termobj(env
, indent
);
1529 AML_DEBUGPRINT(", ");
1530 aml_parse_termobj(env
, indent
);
1531 AML_DEBUGPRINT(")");
1533 case 0x26: /* ResetOp *//* XXX Not yet impremented */
1534 AML_DEBUGPRINT("Reset(");
1535 aml_parse_termobj(env
, indent
);
1536 AML_DEBUGPRINT(")");
1538 case 0x27: /* ReleaseOp *//* XXX Not yet impremented */
1539 AML_DEBUGPRINT("Release(");
1540 aml_parse_termobj(env
, indent
);
1541 AML_DEBUGPRINT(")");
1543 #define NUMOP2(opname, operation) do { \
1544 AML_DEBUGPRINT(opname); \
1545 AML_DEBUGPRINT("("); \
1546 num1 = aml_objtonum(env, aml_eval_name(env, \
1547 aml_parse_termobj(env, indent))); \
1548 AML_DEBUGPRINT(", "); \
1549 anum.num.number = operation (num1); \
1550 destname1 = aml_parse_termobj(env, indent); \
1551 AML_DEBUGPRINT(")"); \
1552 aml_store_to_name(env, &anum, destname1); \
1553 env->tempobject.num = anum.num; \
1554 env->tempname.property = &env->tempobject; \
1555 aname = &env->tempname; \
1558 case 0x28: /* FromBCDOp */
1559 NUMOP2("FromBCD", frombcd
);
1561 case 0x29: /* ToBCDOp */
1562 NUMOP2("ToBCD", tobcd
);
1564 case 0x2a: /* UnloadOp *//* XXX Not yet impremented */
1565 AML_DEBUGPRINT("Unload(");
1566 aml_parse_termobj(env
, indent
);
1567 AML_DEBUGPRINT(")");
1570 env
->tempobject
.type
= aml_t_num
;
1571 env
->tempobject
.num
.number
= 0;
1572 env
->tempobject
.num
.constant
= 1;
1573 AML_DEBUGPRINT("Revision");
1576 env
->tempobject
.type
= aml_t_debug
;
1577 aname
= &env
->tempname
;
1578 AML_DEBUGPRINT("Debug");
1580 case 0x32: /* FatalOp */
1581 AML_DEBUGPRINT("Fatal(");
1582 AML_DEBUGPRINT("0x%x, ", aml_parse_bytedata(env
));
1583 AML_DEBUGPRINT("0x%x, ", aml_parse_dworddata(env
));
1584 aml_parse_termobj(env
, indent
);
1585 env
->stat
= aml_stat_panic
;
1586 AML_DEBUGPRINT(")");
1588 case 0x80: /* OpRegionOp */
1589 aml_parse_defopregion(env
, indent
);
1591 case 0x81: /* FieldOp */
1592 aml_parse_deffield(env
, indent
);
1594 case 0x82: /* DeviceOp */
1595 aml_parse_defdevice(env
, indent
);
1597 case 0x83: /* ProcessorOp */
1598 aml_parse_defprocessor(env
, indent
);
1600 case 0x84: /* PowerResOp */
1601 aml_parse_defpowerres(env
, indent
);
1603 case 0x85: /* ThermalZoneOp */
1604 aml_parse_defthermalzone(env
, indent
);
1606 case 0x86: /* IndexFieldOp */
1607 aml_parse_defindexfield(env
, indent
);
1609 case 0x87: /* BankFieldOp */
1610 aml_parse_defbankfield(env
, indent
);
1613 AML_SYSERRX(1, "strange opcode 0x5b, 0x%x\n", opcode
);
1617 case 0x68 ... 0x6e: /* ArgN */
1618 AML_DEBUGPRINT("Arg%d", opcode
- 0x68);
1619 return (aml_local_stack_getArgX(NULL
, opcode
- 0x68));
1622 AML_DEBUGPRINT("Local%d", opcode
- 0x60);
1623 return (aml_local_stack_getLocalX(opcode
- 0x60));
1625 case 0x70: /* StoreOp */
1626 AML_DEBUGPRINT("Store(");
1627 aname
= aml_create_local_object();
1628 AML_COPY_OBJECT(tmpobj
, env
,
1629 aml_eval_name(env
, aml_parse_termobj(env
, indent
)), NULL
);
1630 aname
->property
= tmpobj
;
1631 AML_DEBUGPRINT(", ");
1632 destname1
= aml_parse_termobj(env
, indent
);
1633 AML_DEBUGPRINT(")");
1635 * temporary object may change during aml_store_to_name()
1636 * operation, so we make a copy of it on stack.
1638 if (destname1
== &env
->tempname
&&
1639 destname1
->property
== &env
->tempobject
) {
1640 destname1
= aml_create_local_object();
1641 AML_COPY_OBJECT(destname1
->property
, env
,
1642 &env
->tempobject
, NULL
);
1644 aml_store_to_name(env
, tmpobj
, destname1
);
1645 if (env
->stat
== aml_stat_panic
) {
1646 AML_DEBUGPRINT("StoreOp failed");
1649 aname
= aml_create_local_object();
1650 AML_COPY_OBJECT(tmpobj
, env
, destname1
->property
, NULL
);
1651 aname
->property
= tmpobj
;
1652 if (tmpobj
== NULL
) {
1657 case 0x71: /* RefOfOp */
1658 AML_DEBUGPRINT("RefOf(");
1659 src
= aml_parse_termobj(env
, indent
);
1660 AML_DEBUGPRINT(")");
1662 aname
= aml_create_local_object();
1663 AML_ALLOC_OBJECT(aname
->property
, env
, aml_t_objref
, NULL
);
1664 objref
= aname
->property
;
1665 if (src
->property
== NULL
||
1666 src
->property
->type
!= aml_t_namestr
) {
1667 objref
->objref
.nameref
= src
;
1669 objref
->objref
.nameref
= aml_create_local_object();
1671 objref
->objref
.ref
= src
->property
;
1672 objref
->objref
.offset
= -1; /* different from IndexOp */
1675 #define NUMOP3_2(opname, oparation, ope2) do { \
1676 AML_DEBUGPRINT(opname); \
1677 AML_DEBUGPRINT("("); \
1678 num1 = aml_objtonum(env, aml_eval_name(env, \
1679 aml_parse_termobj(env, indent))); \
1680 AML_DEBUGPRINT(", "); \
1681 num2 = aml_objtonum(env, aml_eval_name(env, \
1682 aml_parse_termobj(env, indent))); \
1683 AML_DEBUGPRINT(", "); \
1684 anum.num.number = ope2(num1 oparation num2); \
1685 destname1 = aml_parse_termobj(env, indent); \
1686 AML_DEBUGPRINT(")"); \
1687 aml_store_to_name(env, &anum, destname1); \
1688 env->tempobject.num = anum.num; \
1689 env->tempname.property = &env->tempobject; \
1690 aname = &env->tempname; \
1693 #define NUMOP3(opname, operation) NUMOP3_2(opname, operation, )
1694 #define NUMOPN3(opname, operation) NUMOP3_2(opname, operation, ~)
1696 case 0x72: /* AddOp */
1699 case 0x73: /* ConcatOp */
1700 aname
= aml_parse_concatop(env
, indent
);
1702 case 0x74: /* SubtractOp */
1703 NUMOP3("Subtract", -);
1705 case 0x75: /* IncrementOp */
1706 AML_DEBUGPRINT("Increment(");
1707 aname
= aml_parse_termobj(env
, indent
);
1708 num1
= aml_objtonum(env
, aml_eval_name(env
, aname
));
1710 anum
.num
.number
= num1
;
1711 AML_DEBUGPRINT(")");
1712 aml_store_to_name(env
, &anum
, aname
);
1713 aname
= &env
->tempname
;
1714 env
->tempobject
.num
= anum
.num
;
1716 case 0x76: /* DecrementOp */
1717 AML_DEBUGPRINT("Decrement(");
1718 aname
= aml_parse_termobj(env
, indent
);
1719 num1
= aml_objtonum(env
, aml_eval_name(env
, aname
));
1721 anum
.num
.number
= num1
;
1722 AML_DEBUGPRINT(")");
1723 aml_store_to_name(env
, &anum
, aname
);
1724 aname
= &env
->tempname
;
1725 env
->tempobject
.num
= anum
.num
;
1727 case 0x77: /* MultiplyOp */
1728 NUMOP3("Multiply", *);
1730 case 0x78: /* DivideOp */
1731 AML_DEBUGPRINT("Divide(");
1732 num1
= aml_objtonum(env
, aml_eval_name(env
,
1733 aml_parse_termobj(env
, indent
)));
1734 AML_DEBUGPRINT(", ");
1735 num2
= aml_objtonum(env
, aml_eval_name(env
,
1736 aml_parse_termobj(env
, indent
)));
1737 AML_DEBUGPRINT(", ");
1738 anum
.num
.number
= num1
% num2
;
1739 destname1
= aml_parse_termobj(env
, indent
);
1740 aml_store_to_name(env
, &anum
, destname1
);
1741 AML_DEBUGPRINT(", ");
1742 anum
.num
.number
= num1
/ num2
;
1743 destname2
= aml_parse_termobj(env
, indent
);
1744 AML_DEBUGPRINT(")");
1745 aml_store_to_name(env
, &anum
, destname2
);
1746 env
->tempobject
.num
= anum
.num
;
1747 aname
= &env
->tempname
;
1749 case 0x79: /* ShiftLeftOp */
1750 NUMOP3("ShiftLeft", <<);
1752 case 0x7a: /* ShiftRightOp */
1753 NUMOP3("ShiftRight", >>);
1755 case 0x7b: /* AndOp */
1758 case 0x7c: /* NAndOp */
1761 case 0x7d: /* OrOp */
1764 case 0x7e: /* NOrOp */
1767 case 0x7f: /* XOrOp */
1770 case 0x80: /* NotOp */
1773 case 0x81: /* FindSetLeftBitOp */
1774 NUMOP2("FindSetLeftBit", findsetleftbit
);
1776 case 0x82: /* FindSetRightBitOp */
1777 NUMOP2("FindSetRightBit", findsetrightbit
);
1779 case 0x83: /* DerefOp */
1780 AML_DEBUGPRINT("DerefOf(");
1781 objref
= aml_eval_name(env
, aml_parse_termobj(env
, indent
));
1782 AML_DEBUGPRINT(")");
1784 if (objref
->objref
.ref
== NULL
) {
1785 env
->tempname
.property
= objref
->objref
.ref
;
1786 aname
= &env
->tempname
;
1789 switch (objref
->objref
.ref
->type
) {
1792 if (objref
->objref
.offset
< 0) {
1793 env
->tempname
.property
= objref
->objref
.ref
;
1795 objref
->objref
.deref
= 1;
1796 env
->tempname
.property
= objref
;
1800 env
->tempname
.property
= objref
->objref
.ref
;
1804 aname
= &env
->tempname
;
1806 case 0x86: /* NotifyOp *//* XXX Not yet impremented */
1807 AML_DEBUGPRINT("Notify(");
1808 aml_parse_termobj(env
, indent
);
1809 AML_DEBUGPRINT(", ");
1810 aml_parse_termobj(env
, indent
);
1811 AML_DEBUGPRINT(")");
1813 case 0x87: /* SizeOfOp */
1814 AML_DEBUGPRINT("SizeOf(");
1815 aname
= aml_parse_termobj(env
, indent
);
1816 tmpobj
= aml_eval_name(env
, aname
);
1818 AML_DEBUGPRINT(")");
1820 switch (tmpobj
->type
) {
1822 num1
= tmpobj
->buffer
.size
;
1825 num1
= strlen((const char *)tmpobj
->str
.string
);
1828 num1
= tmpobj
->package
.elements
;
1831 AML_DEBUGPRINT("Args of SizeOf should be "
1832 "buffer/string/package only\n");
1836 anum
.num
.number
= num1
;
1837 env
->tempobject
.num
= anum
.num
;
1838 aname
= &env
->tempname
;
1840 case 0x88: /* IndexOp */
1841 AML_DEBUGPRINT("Index(");
1842 srcobj
= aml_eval_name(env
, aml_parse_termobj(env
, indent
));
1843 AML_DEBUGPRINT(", ");
1844 num1
= aml_objtonum(env
, aml_eval_name(env
,
1845 aml_parse_termobj(env
, indent
)));
1846 AML_DEBUGPRINT(", ");
1847 destname1
= aml_parse_termobj(env
, indent
);
1848 AML_DEBUGPRINT(")");
1849 aname
= aml_create_local_object();
1850 switch (srcobj
->type
) {
1853 AML_ALLOC_OBJECT(objref
, env
, aml_t_objref
, NULL
);
1854 aname
->property
= objref
;
1855 objref
->objref
.ref
= srcobj
;
1856 objref
->objref
.offset
= num1
;
1857 objref
->objref
.deref
= 0;
1860 AML_DEBUGPRINT("Arg0 of Index should be either "
1861 "buffer or package\n");
1865 aml_store_to_name(env
, objref
, destname1
);
1867 case 0x89: /* MatchOp *//* XXX Not yet Impremented */
1868 AML_DEBUGPRINT("Match(");
1869 AML_COPY_OBJECT(obj
, env
, aml_eval_name(env
,
1870 aml_parse_termobj(env
, indent
)), NULL
);
1871 if (obj
->type
!= aml_t_package
) {
1872 env
->stat
= aml_stat_panic
;
1875 anum
.num
.number
= 0xffffffff;
1877 AML_DEBUGPRINT(", %d", *env
->dp
);
1879 num1
= aml_objtonum(env
, aml_eval_name(env
,
1880 aml_parse_termobj(env
, indent
)));
1882 AML_DEBUGPRINT(", %d", *env
->dp
);
1884 num2
= aml_objtonum(env
, aml_eval_name(env
,
1885 aml_parse_termobj(env
, indent
)));
1886 AML_DEBUGPRINT(", ");
1887 start
= aml_objtonum(env
, aml_eval_name(env
,
1888 aml_parse_termobj(env
, indent
)));
1890 #define MATCHOP(opnum, arg1, arg2) ((opnum == 0) ? (1) : \
1891 (opnum == 1) ? ((arg1) == (arg2)) : \
1892 (opnum == 2) ? ((arg1) <= (arg2)) : \
1893 (opnum == 3) ? ((arg1) < (arg2)) : \
1894 (opnum == 4) ? ((arg1) >= (arg2)) : \
1895 (opnum == 5) ? ((arg1) > (arg2)) : 0 )
1897 for (i
= start
; i
< obj
->package
.elements
; i
++) {
1898 pkgval
= aml_objtonum(env
, obj
->package
.objects
[i
]);
1899 if (MATCHOP(match1
, pkgval
, num1
) &&
1900 MATCHOP(match2
, pkgval
, num2
)) {
1901 anum
.num
.number
= i
;
1905 AML_DEBUGPRINT(")");
1906 aml_free_object(&obj
);
1907 aname
= &env
->tempname
;
1908 env
->tempname
.property
= &env
->tempobject
;
1909 env
->tempobject
.num
= anum
.num
;
1912 case 0x8a ... 0x8d: /* CreateDWordFieldOp */
1913 widthindex
= *(env
->dp
- 1) - 0x8a;
1914 AML_DEBUGPRINT("%s(", opname
[widthindex
]);
1915 srcbuf
= aml_eval_name(env
, aml_parse_termobj(env
, indent
));
1916 if (srcbuf
== &env
->tempobject
) {
1917 AML_DEBUGPRINT("NOT NAMEDBUF\n");
1918 env
->stat
= aml_stat_panic
;
1921 AML_DEBUGPRINT(", ");
1922 idx
= aml_objtonum(env
, aml_eval_name(env
,
1923 aml_parse_termobj(env
, indent
)));
1924 if (widthindex
!= 3) {
1927 AML_DEBUGPRINT(", ");
1928 newname
= (char *)aml_parse_namestring(env
);
1929 aml_print_namestring((unsigned char *)newname
);
1930 aml_createfield_generic(env
, srcbuf
, idx
,
1931 widthtbl
[widthindex
], newname
);
1932 AML_DEBUGPRINT(")");
1934 case 0x8e: /* ObjectTypeOp */
1935 AML_DEBUGPRINT("ObjectType(");
1936 aname
= aml_parse_termobj(env
, indent
);
1937 if (aname
== NULL
) {
1938 env
->tempobject
.type
= aml_t_num
;
1939 env
->tempobject
.num
.number
= aml_t_null
;
1941 env
->tempobject
.type
= aml_t_num
;
1942 env
->tempobject
.num
.number
= aname
->property
->type
;
1944 aname
= &env
->tempname
;
1945 AML_DEBUGPRINT(")");
1948 #define CMPOP(opname,operation) do { \
1949 AML_DEBUGPRINT(opname); \
1950 AML_DEBUGPRINT("("); \
1951 num1 = aml_objtonum(env, aml_eval_name(env, \
1952 aml_parse_termobj(env, indent))); \
1953 AML_DEBUGPRINT(", "); \
1954 num2 = aml_objtonum(env, aml_eval_name(env, \
1955 aml_parse_termobj(env, indent))); \
1956 aname = &env->tempname; \
1957 env->tempobject.type = aml_t_num; \
1958 env->tempobject.num.number = (num1 operation num2) ? 0xffffffff : 0; \
1959 aname->property = &env->tempobject; \
1960 AML_DEBUGPRINT(")"); \
1970 AML_DEBUGPRINT("LNot(");
1971 num1
= aml_objtonum(env
, aml_eval_name(env
,
1972 aml_parse_termobj(env
, indent
)));
1973 aname
= &env
->tempname
;
1974 env
->tempobject
.type
= aml_t_num
;
1975 env
->tempobject
.num
.number
= (!num1
) ? 0xffffffff : 0;
1976 aname
->property
= &env
->tempobject
;
1977 AML_DEBUGPRINT(")");
1980 CMPOP("LEqual", ==);
1983 CMPOP("LGreater", >);
1988 case 0xa0: /* IfOp */
1989 aname
= aml_parse_defif(env
, indent
);
1993 case 0xa1: /* ElseOp should not be treated in Main parser
1995 aml_parse_defelse(env
, indent
);
1998 case 0xa2: /* WhileOp */
1999 aname
= aml_parse_defwhile(env
, indent
);
2001 case 0xa3: /* NoopOp */
2002 AML_DEBUGPRINT("Noop");
2004 case 0xa5: /* BreakOp */
2005 AML_DEBUGPRINT("Break");
2006 env
->stat
= aml_stat_break
;
2008 case 0xa4: /* ReturnOp */
2009 AML_DEBUGPRINT("Return(");
2010 AML_COPY_OBJECT(env
->tempname
.property
, env
, aml_eval_name(env
,
2011 aml_parse_termobj(env
, indent
)), NULL
);
2012 aname
= &env
->tempname
;
2013 env
->stat
= aml_stat_return
;
2014 AML_DEBUGPRINT(")");
2016 case 0xcc: /* BreakPointOp */
2017 /* XXX Not Yet Impremented (Not need?) */
2018 AML_DEBUGPRINT("BreakPoint");
2021 AML_SYSERRX(1, "strange opcode 0x%x\n", opcode
);