2 /******************************************************************************
4 * Module Name: aslrules.y - Main Bison/Yacc production rules
6 *****************************************************************************/
9 * Copyright (C) 2000 - 2016, Intel Corp.
10 * All rights reserved.
12 * Redistribution and use in source and binary forms, with or without
13 * modification, are permitted provided that the following conditions
15 * 1. Redistributions of source code must retain the above copyright
16 * notice, this list of conditions, and the following disclaimer,
17 * without modification.
18 * 2. Redistributions in binary form must reproduce at minimum a disclaimer
19 * substantially similar to the "NO WARRANTY" disclaimer below
20 * ("Disclaimer") and any redistribution must be conditioned upon
21 * including a substantially similar Disclaimer requirement for further
22 * binary redistribution.
23 * 3. Neither the names of the above-listed copyright holders nor the names
24 * of any contributors may be used to endorse or promote products derived
25 * from this software without specific prior written permission.
27 * Alternatively, this software may be distributed under the terms of the
28 * GNU General Public License ("GPL") version 2 as published by the Free
29 * Software Foundation.
32 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
33 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
34 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
35 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
36 * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
37 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
38 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
39 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
40 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
41 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
42 * POSSIBILITY OF SUCH DAMAGES.
47 /*******************************************************************************
49 * ASL Root and Secondary Terms
51 ******************************************************************************/
54 * Root term. Allow multiple #line directives before the definition block
55 * to handle output from preprocessors
58 : DefinitionBlockList {$<n>$ = TrLinkChildren (
59 TrCreateLeafNode (PARSEOP_ASL_CODE),1, $1);}
60 | error {YYABORT; $$ = NULL;}
65 * Note concerning support for "module-level code".
67 * ACPI 1.0 allowed Type1 and Type2 executable opcodes outside of control
68 * methods (the so-called module-level code.) This support was explicitly
69 * removed in ACPI 2.0, but this type of code continues to be created by
70 * BIOS vendors. In order to support the disassembly and recompilation of
71 * such code (and the porting of ASL code to iASL), iASL supports this
72 * code in violation of the current ACPI specification.
74 * The grammar change to support module-level code is to revert the
75 * {ObjectList} portion of the DefinitionBlockTerm in ACPI 2.0 to the
76 * original use of {TermList} instead (see below.) This allows the use
77 * of Type1 and Type2 opcodes at module level.
79 * 04/2016: The module-level code is now allowed in the following terms:
80 * DeviceTerm, PowerResTerm, ProcessorTerm, ScopeTerm, ThermalZoneTerm.
81 * The ObjectList term is obsolete and has been removed.
84 : PARSEOP_DEFINITION_BLOCK
85 PARSEOP_OPEN_PAREN {$<n>$ = TrCreateLeafNode (PARSEOP_DEFINITION_BLOCK);}
92 PARSEOP_CLOSE_PAREN {TrSetEndLineNumber ($<n>3);}
93 '{' TermList '}' {$$ = TrLinkChildren ($<n>3,7,
94 $4,$6,$8,$10,$12,$14,$18);}
100 DefinitionBlockList {$$ = TrLinkPeerNodes (2, $1,$2);}
104 /******* Basic ASCII identifiers **************************************************/
106 /* Allow IO, DMA, IRQ Resource macro and FOR macro names to also be used as identifiers */
110 | PARSEOP_NAMESTRING {$$ = TrCreateValuedLeafNode (PARSEOP_NAMESTRING, (ACPI_NATIVE_INT) $1);}
111 | PARSEOP_IO {$$ = TrCreateValuedLeafNode (PARSEOP_NAMESTRING, (ACPI_NATIVE_INT) "IO");}
112 | PARSEOP_DMA {$$ = TrCreateValuedLeafNode (PARSEOP_NAMESTRING, (ACPI_NATIVE_INT) "DMA");}
113 | PARSEOP_IRQ {$$ = TrCreateValuedLeafNode (PARSEOP_NAMESTRING, (ACPI_NATIVE_INT) "IRQ");}
114 | PARSEOP_FOR {$$ = TrCreateValuedLeafNode (PARSEOP_NAMESTRING, (ACPI_NATIVE_INT) "FOR");}
118 : PARSEOP_NAMESEG {$$ = TrCreateValuedLeafNode (PARSEOP_NAMESEG, (ACPI_NATIVE_INT)
119 TrNormalizeNameSeg ($1));}
124 : PARSEOP_NAMESEG {$$ = TrCreateValuedLeafNode (PARSEOP_NAMESEG,
125 (ACPI_NATIVE_INT) AslCompilerlval.s);}
129 /******* Fundamental argument/statement types ***********************************/
135 | Type2IntegerOpcode {$$ = TrSetNodeFlags ($1, NODE_COMPILE_TIME_CONST);}
136 | Type2StringOpcode {$$ = TrSetNodeFlags ($1, NODE_COMPILE_TIME_CONST);}
137 | Type2BufferOpcode {}
138 | Type2BufferOrStringOpcode {}
139 | error {$$ = AslDoError(); yyclearin;}
149 : {$$ = TrCreateNullTarget ();} /* Placeholder is a ZeroOp object */
150 | ',' {$$ = TrCreateNullTarget ();} /* Placeholder is a ZeroOp object */
151 | ',' SuperName {$$ = TrSetNodeFlags ($2, NODE_IS_TARGET);}
155 : ',' SuperName {$$ = TrSetNodeFlags ($2, NODE_IS_TARGET);}
159 : SimpleName {$$ = TrSetNodeFlags ($1, NODE_IS_TERM_ARG);}
160 | Type2Opcode {$$ = TrSetNodeFlags ($1, NODE_IS_TERM_ARG);}
161 | DataObject {$$ = TrSetNodeFlags ($1, NODE_IS_TERM_ARG);}
165 PARSEOP_CLOSE_PAREN {}
170 NOTE: Removed from TermArg due to reduce/reduce conflicts:
171 | Type2IntegerOpcode {$$ = TrSetNodeFlags ($1, NODE_IS_TERM_ARG);}
172 | Type2StringOpcode {$$ = TrSetNodeFlags ($1, NODE_IS_TERM_ARG);}
173 | Type2BufferOpcode {$$ = TrSetNodeFlags ($1, NODE_IS_TERM_ARG);}
174 | Type2BufferOrStringOpcode {$$ = TrSetNodeFlags ($1, NODE_IS_TERM_ARG);}
180 PARSEOP_OPEN_PAREN {TrUpdateNode (PARSEOP_METHODCALL, $1);}
182 PARSEOP_CLOSE_PAREN {$$ = TrLinkChildNode ($1,$4);}
185 /* OptionalCount must appear before ByteList or an incorrect reduction will result */
188 : {$$ = TrCreateLeafNode (PARSEOP_ONES);} /* Placeholder is a OnesOp object */
189 | ',' {$$ = TrCreateLeafNode (PARSEOP_ONES);} /* Placeholder is a OnesOp object */
190 | ',' TermArg {$$ = $2;}
194 * Data count for buffers and packages (byte count for buffers,
195 * element count for packages).
203 PARSEOP_CLOSE_PAREN {$$ = $2;}
205 PARSEOP_CLOSE_PAREN {$$ = NULL;}
207 /* C-style (ASL+) -- adds equals term */
209 | PARSEOP_EXP_EQUALS {$$ = NULL;}
214 PARSEOP_EXP_EQUALS {$$ = $2;}
219 PARSEOP_EXP_EQUALS {$$ = NULL;}
223 /******* List Terms **************************************************/
225 /* ACPI 3.0 -- allow semicolons between terms */
229 | TermList Term {$$ = TrLinkPeerNode (
230 TrSetNodeFlags ($1, NODE_RESULT_NOT_USED),$2);}
231 | TermList Term ';' {$$ = TrLinkPeerNode (
232 TrSetNodeFlags ($1, NODE_RESULT_NOT_USED),$2);}
233 | TermList ';' Term {$$ = TrLinkPeerNode (
234 TrSetNodeFlags ($1, NODE_RESULT_NOT_USED),$3);}
235 | TermList ';' Term ';' {$$ = TrLinkPeerNode (
236 TrSetNodeFlags ($1, NODE_RESULT_NOT_USED),$3);}
242 | ArgList ',' /* Allows a trailing comma at list end */
244 TermArg {$$ = TrLinkPeerNode ($1,$3);}
250 | ByteList ',' /* Allows a trailing comma at list end */
252 ByteConstExpr {$$ = TrLinkPeerNode ($1,$3);}
258 | DWordList ',' /* Allows a trailing comma at list end */
260 DWordConstExpr {$$ = TrLinkPeerNode ($1,$3);}
266 | FieldUnitList ',' /* Allows a trailing comma at list end */
268 FieldUnit {$$ = TrLinkPeerNode ($1,$3);}
279 : ',' AmlPackageLengthTerm {$$ = TrCreateNode (PARSEOP_RESERVED_BYTES,1,$2);}
281 AmlPackageLengthTerm {$$ = TrLinkChildNode ($1,$3);}
285 : CompilerDirective {}
287 | NameSpaceModifier {}
288 // | StructureTerm {}
294 | PackageList ',' /* Allows a trailing comma at list end */
296 PackageElement {$$ = TrLinkPeerNode ($1,$3);}
304 /* Rules for specifying the type of one method argument or return value */
308 | ObjectTypeKeyword {$$ = $1;}
309 | ParameterTypePackage ','
310 ObjectTypeKeyword {$$ = TrLinkPeerNodes (2,$1,$3);}
313 ParameterTypePackageList
315 | ObjectTypeKeyword {$$ = $1;}
316 | '{' ParameterTypePackage '}' {$$ = $2;}
319 OptionalParameterTypePackage
320 : {$$ = TrCreateLeafNode (PARSEOP_DEFAULT_ARG);}
321 | ',' ParameterTypePackageList {$$ = TrLinkChildren (
322 TrCreateLeafNode (PARSEOP_DEFAULT_ARG),1,$2);}
325 /* Rules for specifying the types for method arguments */
327 ParameterTypesPackage
328 : ParameterTypePackageList {$$ = $1;}
329 | ParameterTypesPackage ','
330 ParameterTypePackageList {$$ = TrLinkPeerNodes (2,$1,$3);}
333 ParameterTypesPackageList
335 | ObjectTypeKeyword {$$ = $1;}
336 | '{' ParameterTypesPackage '}' {$$ = $2;}
339 OptionalParameterTypesPackage
340 : {$$ = TrCreateLeafNode (PARSEOP_DEFAULT_ARG);}
341 | ',' ParameterTypesPackageList {$$ = TrLinkChildren (
342 TrCreateLeafNode (PARSEOP_DEFAULT_ARG),1,$2);}
346 * Case-Default list; allow only one Default term and unlimited Case terms
352 | CaseDefaultTermList
353 CaseTerm {$$ = TrLinkPeerNode ($1,$2);}
354 | CaseDefaultTermList
355 DefaultTerm {$$ = TrLinkPeerNode ($1,$2);}
357 /* Original - attempts to force zero or one default term within the switch */
364 CaseTermList {$$ = TrLinkPeerNode ($1,TrLinkPeerNode ($2, $3));}
366 CaseTerm {$$ = TrLinkPeerNode ($1,$2);}
373 CaseTerm {$$ = TrLinkPeerNode ($1,$2);}
378 /*******************************************************************************
380 * ASL Data and Constant Terms
382 ******************************************************************************/
392 : Type5Opcode {$$ = TrSetNodeFlags ($1, NODE_COMPILE_TIME_CONST);}
393 | Type2BufferOrStringOpcode {$$ = TrSetNodeFlags ($1, NODE_COMPILE_TIME_CONST);}
394 | Type2BufferOpcode {$$ = TrSetNodeFlags ($1, NODE_COMPILE_TIME_CONST);}
403 : Type2IntegerOpcode {$$ = TrSetNodeFlags ($1, NODE_COMPILE_TIME_CONST);}
404 | Type3Opcode {$$ = TrSetNodeFlags ($1, NODE_COMPILE_TIME_CONST);}
410 : Type2StringOpcode {$$ = TrSetNodeFlags ($1, NODE_COMPILE_TIME_CONST);}
415 : Integer {$$ = TrUpdateNode (PARSEOP_BYTECONST, $1);}
419 : Integer {$$ = TrUpdateNode (PARSEOP_WORDCONST, $1);}
423 : Integer {$$ = TrUpdateNode (PARSEOP_DWORDCONST, $1);}
427 : Integer {$$ = TrUpdateNode (PARSEOP_QWORDCONST, $1);}
431 * The NODE_COMPILE_TIME_CONST flag in the following constant expressions
432 * enables compile-time constant folding to reduce the Type3Opcodes/Type2IntegerOpcodes
433 * to simple integers. It is an error if these types of expressions cannot be
434 * reduced, since the AML grammar for ****ConstExpr requires a simple constant.
435 * Note: The required byte length of the constant is passed through to the
436 * constant folding code in the node AmlLength field.
439 : Type3Opcode {$$ = TrSetNodeFlags ($1, NODE_COMPILE_TIME_CONST);
440 TrSetNodeAmlLength ($1, 1);}
441 | Type2IntegerOpcode {$$ = TrSetNodeFlags ($1, NODE_COMPILE_TIME_CONST);
442 TrSetNodeAmlLength ($1, 1);}
443 | ConstExprTerm {$$ = TrUpdateNode (PARSEOP_BYTECONST, $1);}
448 : Type3Opcode {$$ = TrSetNodeFlags ($1, NODE_COMPILE_TIME_CONST);
449 TrSetNodeAmlLength ($1, 2);}
450 | Type2IntegerOpcode {$$ = TrSetNodeFlags ($1, NODE_COMPILE_TIME_CONST);
451 TrSetNodeAmlLength ($1, 2);}
452 | ConstExprTerm {$$ = TrUpdateNode (PARSEOP_WORDCONST, $1);}
457 : Type3Opcode {$$ = TrSetNodeFlags ($1, NODE_COMPILE_TIME_CONST);
458 TrSetNodeAmlLength ($1, 4);}
459 | Type2IntegerOpcode {$$ = TrSetNodeFlags ($1, NODE_COMPILE_TIME_CONST);
460 TrSetNodeAmlLength ($1, 4);}
461 | ConstExprTerm {$$ = TrUpdateNode (PARSEOP_DWORDCONST, $1);}
466 : Type3Opcode {$$ = TrSetNodeFlags ($1, NODE_COMPILE_TIME_CONST);
467 TrSetNodeAmlLength ($1, 8);}
468 | Type2IntegerOpcode {$$ = TrSetNodeFlags ($1, NODE_COMPILE_TIME_CONST);
469 TrSetNodeAmlLength ($1, 8);}
470 | ConstExprTerm {$$ = TrUpdateNode (PARSEOP_QWORDCONST, $1);}
476 | PARSEOP_REVISION {$$ = TrCreateLeafNode (PARSEOP_REVISION);}
480 : PARSEOP_ZERO {$$ = TrCreateValuedLeafNode (PARSEOP_ZERO, 0);}
481 | PARSEOP_ONE {$$ = TrCreateValuedLeafNode (PARSEOP_ONE, 1);}
482 | PARSEOP_ONES {$$ = TrCreateValuedLeafNode (PARSEOP_ONES, ACPI_UINT64_MAX);}
483 | PARSEOP___DATE__ {$$ = TrCreateConstantLeafNode (PARSEOP___DATE__);}
484 | PARSEOP___FILE__ {$$ = TrCreateConstantLeafNode (PARSEOP___FILE__);}
485 | PARSEOP___LINE__ {$$ = TrCreateConstantLeafNode (PARSEOP___LINE__);}
486 | PARSEOP___PATH__ {$$ = TrCreateConstantLeafNode (PARSEOP___PATH__);}
490 : PARSEOP_INTEGER {$$ = TrCreateValuedLeafNode (PARSEOP_INTEGER,
495 : PARSEOP_STRING_LITERAL {$$ = TrCreateValuedLeafNode (PARSEOP_STRING_LITERAL,
496 (ACPI_NATIVE_INT) AslCompilerlval.s);}
500 /*******************************************************************************
504 ******************************************************************************/
514 | CreateBitFieldTerm {}
515 | CreateByteFieldTerm {}
516 | CreateDWordFieldTerm {}
518 | CreateQWordFieldTerm {}
519 | CreateWordFieldTerm {}
537 // | NameTermAslPlus {}
547 /* For ObjectType(), SuperName except for MethodInvocationTerm */
558 /* For DeRefOf(), SuperName except for DerefOf and Debug */
568 | MethodInvocationTerm {}
571 /* For RefOf(), SuperName except for RefOf and MethodInvocationTerm */
581 /* For CondRefOf(), SuperName except for RefOf and MethodInvocationTerm */
592 * Opcode types, as defined in the ACPI specification
627 | MethodInvocationTerm {}
633 Type2IntegerOpcode /* "Type3" opcodes */
634 : Expression {$$ = TrSetNodeFlags ($1, NODE_COMPILE_TIME_CONST);}
639 | FindSetLeftBitTerm {}
640 | FindSetRightBitTerm {}
644 // | StructureIndexTerm {}
645 // | StructurePointerTerm {}
649 | LGreaterEqualTerm {}
671 Type2StringOpcode /* "Type4" Opcodes */
672 : ToDecimalStringTerm {}
677 Type2BufferOpcode /* "Type5" Opcodes */
682 Type2BufferOrStringOpcode
683 : ConcatTerm {$$ = TrSetNodeFlags ($1, NODE_COMPILE_TIME_CONST);}
690 * A type 3 opcode evaluates to an Integer and cannot have a destination operand
699 | ToDecimalStringTerm {}
706 /* Type 5 opcodes are a subset of Type2 opcodes, and return a constant */
709 : ResourceTemplateTerm {}
720 // | StructureIndexTerm {}
721 // | StructurePointerTerm {}
722 | MethodInvocationTerm {}
726 /*******************************************************************************
730 ******************************************************************************/
733 : Integer {$$ = TrUpdateNode (PARSEOP_PACKAGE_LENGTH,
734 (ACPI_PARSE_OBJECT *) $1);}
738 : ',' NameString {$$ = $2;}
739 | ',' error {$$ = AslDoError (); yyclearin;}
743 : ',' TermArg {$$ = $2;}
744 | ',' error {$$ = AslDoError (); yyclearin;}
748 : {$$ = TrCreateLeafNode (PARSEOP_ZERO);} /* Placeholder is a ZeroOp object */
749 | ',' {$$ = TrCreateLeafNode (PARSEOP_ZERO);} /* Placeholder is a ZeroOp object */
750 | ',' TermArg {$$ = $2;}
754 : {$$ = TrSetNodeFlags (TrCreateLeafNode (PARSEOP_ZERO),
755 NODE_IS_NULL_RETURN);} /* Placeholder is a ZeroOp object */
759 OptionalSerializeRuleKeyword
762 | ',' SerializeRuleKeyword {$$ = $2;}
766 : {$$ = TrCreateLeafNode (PARSEOP_DEFAULT_ARG);}
772 | WordConst {$$ = $1;}