2 /******************************************************************************
4 * Module Name: aslrules.y - Main Bison/Yacc production rules
5 * - Keep this file synched with the
6 * CvParseOpBlockType function in cvcompiler.c
8 *****************************************************************************/
11 * Copyright (C) 2000 - 2017, Intel Corp.
12 * All rights reserved.
14 * Redistribution and use in source and binary forms, with or without
15 * modification, are permitted provided that the following conditions
17 * 1. Redistributions of source code must retain the above copyright
18 * notice, this list of conditions, and the following disclaimer,
19 * without modification.
20 * 2. Redistributions in binary form must reproduce at minimum a disclaimer
21 * substantially similar to the "NO WARRANTY" disclaimer below
22 * ("Disclaimer") and any redistribution must be conditioned upon
23 * including a substantially similar Disclaimer requirement for further
24 * binary redistribution.
25 * 3. Neither the names of the above-listed copyright holders nor the names
26 * of any contributors may be used to endorse or promote products derived
27 * from this software without specific prior written permission.
29 * Alternatively, this software may be distributed under the terms of the
30 * GNU General Public License ("GPL") version 2 as published by the Free
31 * Software Foundation.
34 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
35 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
36 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
37 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
38 * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
39 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
40 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
41 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
42 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
43 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
44 * POSSIBILITY OF SUCH DAMAGES.
49 /*******************************************************************************
51 * ASL Root and Secondary Terms
53 ******************************************************************************/
56 * Root term. Allow multiple #line directives before the definition block
57 * to handle output from preprocessors
60 : DefinitionBlockList
{$
<n
>$
= TrLinkChildren
(
61 TrCreateLeafNode
(PARSEOP_ASL_CODE
),1, $1);}
62 |
error {YYABORT; $$
= NULL
;}
67 * Note concerning support for "module-level code".
69 * ACPI 1.0 allowed Type1 and Type2 executable opcodes outside of control
70 * methods (the so-called module-level code.) This support was explicitly
71 * removed in ACPI 2.0, but this type of code continues to be created by
72 * BIOS vendors. In order to support the disassembly and recompilation of
73 * such code (and the porting of ASL code to iASL), iASL supports this
74 * code in violation of the current ACPI specification.
76 * The grammar change to support module-level code is to revert the
77 * {ObjectList} portion of the DefinitionBlockTerm in ACPI 2.0 to the
78 * original use of {TermList} instead (see below.) This allows the use
79 * of Type1 and Type2 opcodes at module level.
81 * 04/2016: The module-level code is now allowed in the following terms:
82 * DeviceTerm, PowerResTerm, ProcessorTerm, ScopeTerm, ThermalZoneTerm.
83 * The ObjectList term is obsolete and has been removed.
86 : PARSEOP_DEFINITION_BLOCK
87 PARSEOP_OPEN_PAREN
{$
<n
>$
= TrCreateLeafNode
(PARSEOP_DEFINITION_BLOCK
); COMMENT_CAPTURE_OFF
;}
94 PARSEOP_CLOSE_PAREN
{TrSetEndLineNumber
($
<n
>3); COMMENT_CAPTURE_ON
;}
95 '{' TermList
'}' {$$
= TrLinkChildren
($
<n
>3,7,
96 $4,$6,$8,$10,$12,$14,$18);}
100 : DefinitionBlockTerm
101 | DefinitionBlockTerm
102 DefinitionBlockList
{$$
= TrLinkPeerNodes
(2, $1,$2);}
106 /******* Basic ASCII identifiers **************************************************/
108 /* Allow IO, DMA, IRQ Resource macro and FOR macro names to also be used as identifiers */
112 | PARSEOP_NAMESTRING
{$$
= TrCreateValuedLeafNode
(PARSEOP_NAMESTRING
, (ACPI_NATIVE_INT
) $1);}
113 | PARSEOP_IO
{$$
= TrCreateValuedLeafNode
(PARSEOP_NAMESTRING
, (ACPI_NATIVE_INT
) "IO");}
114 | PARSEOP_DMA
{$$
= TrCreateValuedLeafNode
(PARSEOP_NAMESTRING
, (ACPI_NATIVE_INT
) "DMA");}
115 | PARSEOP_IRQ
{$$
= TrCreateValuedLeafNode
(PARSEOP_NAMESTRING
, (ACPI_NATIVE_INT
) "IRQ");}
116 | PARSEOP_FOR
{$$
= TrCreateValuedLeafNode
(PARSEOP_NAMESTRING
, (ACPI_NATIVE_INT
) "FOR");}
120 : PARSEOP_NAMESEG {$$ = TrCreateValuedLeafNode (PARSEOP_NAMESEG, (ACPI_NATIVE_INT)
121 TrNormalizeNameSeg ($1));}
126 : PARSEOP_NAMESEG
{$$
= TrCreateValuedLeafNode
(PARSEOP_NAMESEG
,
127 (ACPI_NATIVE_INT
) AslCompilerlval.s
);}
131 /******* Fundamental argument/statement types ***********************************/
137 | Type2IntegerOpcode
{$$
= TrSetNodeFlags
($1, NODE_COMPILE_TIME_CONST
);}
138 | Type2StringOpcode
{$$
= TrSetNodeFlags
($1, NODE_COMPILE_TIME_CONST
);}
139 | Type2BufferOpcode
{}
140 | Type2BufferOrStringOpcode
{}
141 |
error {$$
= AslDoError
(); yyclearin;}
151 : {$$
= TrCreateNullTarget
();} /* Placeholder is a ZeroOp object */
152 |
',' {$$
= TrCreateNullTarget
();} /* Placeholder is a ZeroOp object */
153 |
',' SuperName
{$$
= TrSetNodeFlags
($2, NODE_IS_TARGET
);}
157 : ',' SuperName
{$$
= TrSetNodeFlags
($2, NODE_IS_TARGET
);}
161 : SimpleName
{$$
= TrSetNodeFlags
($1, NODE_IS_TERM_ARG
);}
162 | Type2Opcode
{$$
= TrSetNodeFlags
($1, NODE_IS_TERM_ARG
);}
163 | DataObject
{$$
= TrSetNodeFlags
($1, NODE_IS_TERM_ARG
);}
167 PARSEOP_CLOSE_PAREN {}
172 NOTE: Removed from TermArg due to reduce/reduce conflicts:
173 | Type2IntegerOpcode {$$ = TrSetNodeFlags ($1, NODE_IS_TERM_ARG);}
174 | Type2StringOpcode {$$ = TrSetNodeFlags ($1, NODE_IS_TERM_ARG);}
175 | Type2BufferOpcode {$$ = TrSetNodeFlags ($1, NODE_IS_TERM_ARG);}
176 | Type2BufferOrStringOpcode {$$ = TrSetNodeFlags ($1, NODE_IS_TERM_ARG);}
182 PARSEOP_OPEN_PAREN
{TrUpdateNode
(PARSEOP_METHODCALL
, $1); COMMENT_CAPTURE_OFF
;}
184 PARSEOP_CLOSE_PAREN
{$$
= TrLinkChildNode
($1,$4); COMMENT_CAPTURE_ON
;}
187 /* OptionalCount must appear before ByteList or an incorrect reduction will result */
190 : {$$
= TrCreateLeafNode
(PARSEOP_ONES
);} /* Placeholder is a OnesOp object */
191 |
',' {$$
= TrCreateLeafNode
(PARSEOP_ONES
);} /* Placeholder is a OnesOp object */
192 |
',' TermArg
{$$
= $2;}
196 * Data count for buffers and packages (byte count for buffers,
197 * element count for packages).
205 PARSEOP_CLOSE_PAREN
{$$
= $2;}
207 PARSEOP_CLOSE_PAREN
{$$
= NULL
;}
209 /* C-style (ASL+) -- adds equals term */
211 | PARSEOP_EXP_EQUALS
{$$
= NULL
;}
216 PARSEOP_EXP_EQUALS
{$$
= $2;}
221 PARSEOP_EXP_EQUALS
{$$
= NULL
;}
225 /******* List Terms **************************************************/
227 /* ACPI 3.0 -- allow semicolons between terms */
231 | TermList Term
{$$
= TrLinkPeerNode
(
232 TrSetNodeFlags
($1, NODE_RESULT_NOT_USED
),$2);}
233 | TermList Term
';' {$$
= TrLinkPeerNode
(
234 TrSetNodeFlags
($1, NODE_RESULT_NOT_USED
),$2);}
235 | TermList
';' Term
{$$
= TrLinkPeerNode
(
236 TrSetNodeFlags
($1, NODE_RESULT_NOT_USED
),$3);}
237 | TermList
';' Term
';' {$$
= TrLinkPeerNode
(
238 TrSetNodeFlags
($1, NODE_RESULT_NOT_USED
),$3);}
244 | ArgList
',' /* Allows a trailing comma at list end */
246 TermArg
{$$
= TrLinkPeerNode
($1,$3);}
252 | ByteList
',' /* Allows a trailing comma at list end */
254 ByteConstExpr
{$$
= TrLinkPeerNode
($1,$3);}
260 | DWordList
',' /* Allows a trailing comma at list end */
262 DWordConstExpr
{$$
= TrLinkPeerNode
($1,$3);}
268 | FieldUnitList
',' /* Allows a trailing comma at list end */
270 FieldUnit
{$$
= TrLinkPeerNode
($1,$3);}
281 : ',' AmlPackageLengthTerm
{$$
= TrCreateNode
(PARSEOP_RESERVED_BYTES
,1,$2);}
283 AmlPackageLengthTerm
{$$
= TrLinkChildNode
($1,$3);}
287 : CompilerDirective
{}
289 | NameSpaceModifier
{}
290 // | StructureTerm {}
296 | PackageList
',' /* Allows a trailing comma at list end */
298 PackageElement
{$$
= TrLinkPeerNode
($1,$3);}
306 /* Rules for specifying the type of one method argument or return value */
310 | ObjectTypeKeyword
{$$
= $1;}
311 | ParameterTypePackage
','
312 ObjectTypeKeyword
{$$
= TrLinkPeerNodes
(2,$1,$3);}
315 ParameterTypePackageList
317 | ObjectTypeKeyword
{$$
= $1;}
318 |
'{' ParameterTypePackage
'}' {$$
= $2;}
321 OptionalParameterTypePackage
322 : {$$
= TrCreateLeafNode
(PARSEOP_DEFAULT_ARG
);}
323 |
',' ParameterTypePackageList
{$$
= TrLinkChildren
(
324 TrCreateLeafNode
(PARSEOP_DEFAULT_ARG
),1,$2);}
327 /* Rules for specifying the types for method arguments */
329 ParameterTypesPackage
330 : ParameterTypePackageList
{$$
= $1;}
331 | ParameterTypesPackage
','
332 ParameterTypePackageList
{$$
= TrLinkPeerNodes
(2,$1,$3);}
335 ParameterTypesPackageList
337 | ObjectTypeKeyword
{$$
= $1;}
338 |
'{' ParameterTypesPackage
'}' {$$
= $2;}
341 OptionalParameterTypesPackage
342 : {$$
= TrCreateLeafNode
(PARSEOP_DEFAULT_ARG
);}
343 |
',' ParameterTypesPackageList
{$$
= TrLinkChildren
(
344 TrCreateLeafNode
(PARSEOP_DEFAULT_ARG
),1,$2);}
348 * Case-Default list; allow only one Default term and unlimited Case terms
354 | CaseDefaultTermList
355 CaseTerm
{$$
= TrLinkPeerNode
($1,$2);}
356 | CaseDefaultTermList
357 DefaultTerm
{$$
= TrLinkPeerNode
($1,$2);}
359 /* Original - attempts to force zero or one default term within the switch */
366 CaseTermList {$$ = TrLinkPeerNode ($1,TrLinkPeerNode ($2, $3));}
368 CaseTerm {$$ = TrLinkPeerNode ($1,$2);}
375 CaseTerm {$$ = TrLinkPeerNode ($1,$2);}
380 /*******************************************************************************
382 * ASL Data and Constant Terms
384 ******************************************************************************/
394 : Type5Opcode
{$$
= TrSetNodeFlags
($1, NODE_COMPILE_TIME_CONST
);}
395 | Type2BufferOrStringOpcode
{$$
= TrSetNodeFlags
($1, NODE_COMPILE_TIME_CONST
);}
396 | Type2BufferOpcode
{$$
= TrSetNodeFlags
($1, NODE_COMPILE_TIME_CONST
);}
405 : Type2IntegerOpcode
{$$
= TrSetNodeFlags
($1, NODE_COMPILE_TIME_CONST
);}
406 | Type3Opcode
{$$
= TrSetNodeFlags
($1, NODE_COMPILE_TIME_CONST
);}
412 : Type2StringOpcode
{$$
= TrSetNodeFlags
($1, NODE_COMPILE_TIME_CONST
);}
417 : Integer
{$$
= TrUpdateNode
(PARSEOP_BYTECONST
, $1);}
421 : Integer
{$$
= TrUpdateNode
(PARSEOP_WORDCONST
, $1);}
425 : Integer
{$$
= TrUpdateNode
(PARSEOP_DWORDCONST
, $1);}
429 : Integer
{$$
= TrUpdateNode
(PARSEOP_QWORDCONST
, $1);}
433 * The NODE_COMPILE_TIME_CONST flag in the following constant expressions
434 * enables compile-time constant folding to reduce the Type3Opcodes/Type2IntegerOpcodes
435 * to simple integers. It is an error if these types of expressions cannot be
436 * reduced, since the AML grammar for ****ConstExpr requires a simple constant.
437 * Note: The required byte length of the constant is passed through to the
438 * constant folding code in the node AmlLength field.
441 : Type3Opcode
{$$
= TrSetNodeFlags
($1, NODE_COMPILE_TIME_CONST
);
442 TrSetNodeAmlLength
($1, 1);}
443 | Type2IntegerOpcode
{$$
= TrSetNodeFlags
($1, NODE_COMPILE_TIME_CONST
);
444 TrSetNodeAmlLength
($1, 1);}
445 | ConstExprTerm
{$$
= TrUpdateNode
(PARSEOP_BYTECONST
, $1);}
450 : Type3Opcode
{$$
= TrSetNodeFlags
($1, NODE_COMPILE_TIME_CONST
);
451 TrSetNodeAmlLength
($1, 2);}
452 | Type2IntegerOpcode
{$$
= TrSetNodeFlags
($1, NODE_COMPILE_TIME_CONST
);
453 TrSetNodeAmlLength
($1, 2);}
454 | ConstExprTerm
{$$
= TrUpdateNode
(PARSEOP_WORDCONST
, $1);}
459 : Type3Opcode
{$$
= TrSetNodeFlags
($1, NODE_COMPILE_TIME_CONST
);
460 TrSetNodeAmlLength
($1, 4);}
461 | Type2IntegerOpcode
{$$
= TrSetNodeFlags
($1, NODE_COMPILE_TIME_CONST
);
462 TrSetNodeAmlLength
($1, 4);}
463 | ConstExprTerm
{$$
= TrUpdateNode
(PARSEOP_DWORDCONST
, $1);}
468 : Type3Opcode
{$$
= TrSetNodeFlags
($1, NODE_COMPILE_TIME_CONST
);
469 TrSetNodeAmlLength
($1, 8);}
470 | Type2IntegerOpcode
{$$
= TrSetNodeFlags
($1, NODE_COMPILE_TIME_CONST
);
471 TrSetNodeAmlLength
($1, 8);}
472 | ConstExprTerm
{$$
= TrUpdateNode
(PARSEOP_QWORDCONST
, $1);}
478 | PARSEOP_REVISION
{$$
= TrCreateLeafNode
(PARSEOP_REVISION
);}
482 : PARSEOP_ZERO
{$$
= TrCreateValuedLeafNode
(PARSEOP_ZERO
, 0);}
483 | PARSEOP_ONE
{$$
= TrCreateValuedLeafNode
(PARSEOP_ONE
, 1);}
484 | PARSEOP_ONES
{$$
= TrCreateValuedLeafNode
(PARSEOP_ONES
, ACPI_UINT64_MAX
);}
485 | PARSEOP___DATE__
{$$
= TrCreateConstantLeafNode
(PARSEOP___DATE__
);}
486 | PARSEOP___FILE__
{$$
= TrCreateConstantLeafNode
(PARSEOP___FILE__
);}
487 | PARSEOP___LINE__
{$$
= TrCreateConstantLeafNode
(PARSEOP___LINE__
);}
488 | PARSEOP___PATH__
{$$
= TrCreateConstantLeafNode
(PARSEOP___PATH__
);}
492 : PARSEOP_INTEGER
{$$
= TrCreateValuedLeafNode
(PARSEOP_INTEGER
,
497 : PARSEOP_STRING_LITERAL
{$$
= TrCreateValuedLeafNode
(PARSEOP_STRING_LITERAL
,
498 (ACPI_NATIVE_INT
) AslCompilerlval.s
);}
502 /*******************************************************************************
506 ******************************************************************************/
516 | CreateBitFieldTerm
{}
517 | CreateByteFieldTerm
{}
518 | CreateDWordFieldTerm
{}
520 | CreateQWordFieldTerm
{}
521 | CreateWordFieldTerm
{}
539 // | NameTermAslPlus {}
549 /* For ObjectType(), SuperName except for MethodInvocationTerm */
560 /* For DeRefOf(), SuperName except for DerefOf and Debug */
570 | MethodInvocationTerm
{}
573 /* For RefOf(), SuperName except for RefOf and MethodInvocationTerm */
583 /* For CondRefOf(), SuperName except for RefOf and MethodInvocationTerm */
594 * Opcode types, as defined in the ACPI specification
629 | MethodInvocationTerm
{}
635 Type2IntegerOpcode
/* "Type3" opcodes */
636 : Expression
{$$
= TrSetNodeFlags
($1, NODE_COMPILE_TIME_CONST
);}
641 | FindSetLeftBitTerm
{}
642 | FindSetRightBitTerm
{}
646 // | StructureIndexTerm {}
647 // | StructurePointerTerm {}
651 | LGreaterEqualTerm
{}
673 Type2StringOpcode
/* "Type4" Opcodes */
674 : ToDecimalStringTerm
{}
679 Type2BufferOpcode
/* "Type5" Opcodes */
684 Type2BufferOrStringOpcode
685 : ConcatTerm
{$$
= TrSetNodeFlags
($1, NODE_COMPILE_TIME_CONST
);}
692 * A type 3 opcode evaluates to an Integer and cannot have a destination operand
701 | ToDecimalStringTerm {}
708 /* Type 5 opcodes are a subset of Type2 opcodes, and return a constant */
711 : ResourceTemplateTerm
{}
722 // | StructureIndexTerm {}
723 // | StructurePointerTerm {}
724 | MethodInvocationTerm
{}
728 /*******************************************************************************
732 ******************************************************************************/
735 : Integer
{$$
= TrUpdateNode
(PARSEOP_PACKAGE_LENGTH
,
736 (ACPI_PARSE_OBJECT
*) $1);}
740 : ',' NameString
{$$
= $2;}
741 |
',' error {$$
= AslDoError
(); yyclearin;}
745 : ',' TermArg
{$$
= $2;}
746 |
',' error {$$
= AslDoError
(); yyclearin;}
750 : {$$
= TrCreateLeafNode
(PARSEOP_ZERO
);} /* Placeholder is a ZeroOp object */
751 |
',' {$$
= TrCreateLeafNode
(PARSEOP_ZERO
);} /* Placeholder is a ZeroOp object */
752 |
',' TermArg
{$$
= $2;}
756 : {$$
= TrSetNodeFlags
(TrCreateLeafNode
(PARSEOP_ZERO
),
757 NODE_IS_NULL_RETURN
);} /* Placeholder is a ZeroOp object */
761 OptionalSerializeRuleKeyword
764 |
',' SerializeRuleKeyword
{$$
= $2;}
768 : {$$
= TrCreateLeafNode
(PARSEOP_DEFAULT_ARG
);}
774 | WordConst
{$$
= $1;}