1bc36eafdSMike Gerdts /******************************************************************************
2bc36eafdSMike Gerdts *
3*35786f68SRobert Mustacchi * Module Name: asltree - Parse tree management
4bc36eafdSMike Gerdts *
5bc36eafdSMike Gerdts *****************************************************************************/
6bc36eafdSMike Gerdts
7*35786f68SRobert Mustacchi /******************************************************************************
8*35786f68SRobert Mustacchi *
9*35786f68SRobert Mustacchi * 1. Copyright Notice
10*35786f68SRobert Mustacchi *
11*35786f68SRobert Mustacchi * Some or all of this work - Copyright (c) 1999 - 2018, Intel Corp.
12bc36eafdSMike Gerdts * All rights reserved.
13bc36eafdSMike Gerdts *
14*35786f68SRobert Mustacchi * 2. License
15*35786f68SRobert Mustacchi *
16*35786f68SRobert Mustacchi * 2.1. This is your license from Intel Corp. under its intellectual property
17*35786f68SRobert Mustacchi * rights. You may have additional license terms from the party that provided
18*35786f68SRobert Mustacchi * you this software, covering your right to use that party's intellectual
19*35786f68SRobert Mustacchi * property rights.
20*35786f68SRobert Mustacchi *
21*35786f68SRobert Mustacchi * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
22*35786f68SRobert Mustacchi * copy of the source code appearing in this file ("Covered Code") an
23*35786f68SRobert Mustacchi * irrevocable, perpetual, worldwide license under Intel's copyrights in the
24*35786f68SRobert Mustacchi * base code distributed originally by Intel ("Original Intel Code") to copy,
25*35786f68SRobert Mustacchi * make derivatives, distribute, use and display any portion of the Covered
26*35786f68SRobert Mustacchi * Code in any form, with the right to sublicense such rights; and
27*35786f68SRobert Mustacchi *
28*35786f68SRobert Mustacchi * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
29*35786f68SRobert Mustacchi * license (with the right to sublicense), under only those claims of Intel
30*35786f68SRobert Mustacchi * patents that are infringed by the Original Intel Code, to make, use, sell,
31*35786f68SRobert Mustacchi * offer to sell, and import the Covered Code and derivative works thereof
32*35786f68SRobert Mustacchi * solely to the minimum extent necessary to exercise the above copyright
33*35786f68SRobert Mustacchi * license, and in no event shall the patent license extend to any additions
34*35786f68SRobert Mustacchi * to or modifications of the Original Intel Code. No other license or right
35*35786f68SRobert Mustacchi * is granted directly or by implication, estoppel or otherwise;
36*35786f68SRobert Mustacchi *
37*35786f68SRobert Mustacchi * The above copyright and patent license is granted only if the following
38*35786f68SRobert Mustacchi * conditions are met:
39*35786f68SRobert Mustacchi *
40*35786f68SRobert Mustacchi * 3. Conditions
41*35786f68SRobert Mustacchi *
42*35786f68SRobert Mustacchi * 3.1. Redistribution of Source with Rights to Further Distribute Source.
43*35786f68SRobert Mustacchi * Redistribution of source code of any substantial portion of the Covered
44*35786f68SRobert Mustacchi * Code or modification with rights to further distribute source must include
45*35786f68SRobert Mustacchi * the above Copyright Notice, the above License, this list of Conditions,
46*35786f68SRobert Mustacchi * and the following Disclaimer and Export Compliance provision. In addition,
47*35786f68SRobert Mustacchi * Licensee must cause all Covered Code to which Licensee contributes to
48*35786f68SRobert Mustacchi * contain a file documenting the changes Licensee made to create that Covered
49*35786f68SRobert Mustacchi * Code and the date of any change. Licensee must include in that file the
50*35786f68SRobert Mustacchi * documentation of any changes made by any predecessor Licensee. Licensee
51*35786f68SRobert Mustacchi * must include a prominent statement that the modification is derived,
52*35786f68SRobert Mustacchi * directly or indirectly, from Original Intel Code.
53*35786f68SRobert Mustacchi *
54*35786f68SRobert Mustacchi * 3.2. Redistribution of Source with no Rights to Further Distribute Source.
55*35786f68SRobert Mustacchi * Redistribution of source code of any substantial portion of the Covered
56*35786f68SRobert Mustacchi * Code or modification without rights to further distribute source must
57*35786f68SRobert Mustacchi * include the following Disclaimer and Export Compliance provision in the
58*35786f68SRobert Mustacchi * documentation and/or other materials provided with distribution. In
59*35786f68SRobert Mustacchi * addition, Licensee may not authorize further sublicense of source of any
60*35786f68SRobert Mustacchi * portion of the Covered Code, and must include terms to the effect that the
61*35786f68SRobert Mustacchi * license from Licensee to its licensee is limited to the intellectual
62*35786f68SRobert Mustacchi * property embodied in the software Licensee provides to its licensee, and
63*35786f68SRobert Mustacchi * not to intellectual property embodied in modifications its licensee may
64*35786f68SRobert Mustacchi * make.
65*35786f68SRobert Mustacchi *
66*35786f68SRobert Mustacchi * 3.3. Redistribution of Executable. Redistribution in executable form of any
67*35786f68SRobert Mustacchi * substantial portion of the Covered Code or modification must reproduce the
68*35786f68SRobert Mustacchi * above Copyright Notice, and the following Disclaimer and Export Compliance
69*35786f68SRobert Mustacchi * provision in the documentation and/or other materials provided with the
70*35786f68SRobert Mustacchi * distribution.
71*35786f68SRobert Mustacchi *
72*35786f68SRobert Mustacchi * 3.4. Intel retains all right, title, and interest in and to the Original
73*35786f68SRobert Mustacchi * Intel Code.
74*35786f68SRobert Mustacchi *
75*35786f68SRobert Mustacchi * 3.5. Neither the name Intel nor any other trademark owned or controlled by
76*35786f68SRobert Mustacchi * Intel shall be used in advertising or otherwise to promote the sale, use or
77*35786f68SRobert Mustacchi * other dealings in products derived from or relating to the Covered Code
78*35786f68SRobert Mustacchi * without prior written authorization from Intel.
79*35786f68SRobert Mustacchi *
80*35786f68SRobert Mustacchi * 4. Disclaimer and Export Compliance
81*35786f68SRobert Mustacchi *
82*35786f68SRobert Mustacchi * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
83*35786f68SRobert Mustacchi * HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
84*35786f68SRobert Mustacchi * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE,
85*35786f68SRobert Mustacchi * INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY
86*35786f68SRobert Mustacchi * UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY
87*35786f68SRobert Mustacchi * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
88*35786f68SRobert Mustacchi * PARTICULAR PURPOSE.
89*35786f68SRobert Mustacchi *
90*35786f68SRobert Mustacchi * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
91*35786f68SRobert Mustacchi * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
92*35786f68SRobert Mustacchi * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
93*35786f68SRobert Mustacchi * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
94*35786f68SRobert Mustacchi * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
95*35786f68SRobert Mustacchi * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS
96*35786f68SRobert Mustacchi * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
97*35786f68SRobert Mustacchi * LIMITED REMEDY.
98*35786f68SRobert Mustacchi *
99*35786f68SRobert Mustacchi * 4.3. Licensee shall not export, either directly or indirectly, any of this
100*35786f68SRobert Mustacchi * software or system incorporating such software without first obtaining any
101*35786f68SRobert Mustacchi * required license or other approval from the U. S. Department of Commerce or
102*35786f68SRobert Mustacchi * any other agency or department of the United States Government. In the
103*35786f68SRobert Mustacchi * event Licensee exports any such software from the United States or
104*35786f68SRobert Mustacchi * re-exports any such software from a foreign destination, Licensee shall
105*35786f68SRobert Mustacchi * ensure that the distribution and export/re-export of the software is in
106*35786f68SRobert Mustacchi * compliance with all laws, regulations, orders, or other restrictions of the
107*35786f68SRobert Mustacchi * U.S. Export Administration Regulations. Licensee agrees that neither it nor
108*35786f68SRobert Mustacchi * any of its subsidiaries will export/re-export any technical data, process,
109*35786f68SRobert Mustacchi * software, or service, directly or indirectly, to any country for which the
110*35786f68SRobert Mustacchi * United States government or any agency thereof requires an export license,
111*35786f68SRobert Mustacchi * other governmental approval, or letter of assurance, without first obtaining
112*35786f68SRobert Mustacchi * such license, approval or letter.
113*35786f68SRobert Mustacchi *
114*35786f68SRobert Mustacchi *****************************************************************************
115*35786f68SRobert Mustacchi *
116*35786f68SRobert Mustacchi * Alternatively, you may choose to be licensed under the terms of the
117*35786f68SRobert Mustacchi * following license:
118*35786f68SRobert Mustacchi *
119bc36eafdSMike Gerdts * Redistribution and use in source and binary forms, with or without
120bc36eafdSMike Gerdts * modification, are permitted provided that the following conditions
121bc36eafdSMike Gerdts * are met:
122bc36eafdSMike Gerdts * 1. Redistributions of source code must retain the above copyright
123bc36eafdSMike Gerdts * notice, this list of conditions, and the following disclaimer,
124bc36eafdSMike Gerdts * without modification.
125bc36eafdSMike Gerdts * 2. Redistributions in binary form must reproduce at minimum a disclaimer
126bc36eafdSMike Gerdts * substantially similar to the "NO WARRANTY" disclaimer below
127bc36eafdSMike Gerdts * ("Disclaimer") and any redistribution must be conditioned upon
128bc36eafdSMike Gerdts * including a substantially similar Disclaimer requirement for further
129bc36eafdSMike Gerdts * binary redistribution.
130bc36eafdSMike Gerdts * 3. Neither the names of the above-listed copyright holders nor the names
131bc36eafdSMike Gerdts * of any contributors may be used to endorse or promote products derived
132bc36eafdSMike Gerdts * from this software without specific prior written permission.
133bc36eafdSMike Gerdts *
134bc36eafdSMike Gerdts * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
135bc36eafdSMike Gerdts * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
136*35786f68SRobert Mustacchi * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
137bc36eafdSMike Gerdts * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
138*35786f68SRobert Mustacchi * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
139*35786f68SRobert Mustacchi * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
140*35786f68SRobert Mustacchi * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
141*35786f68SRobert Mustacchi * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
142*35786f68SRobert Mustacchi * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
143*35786f68SRobert Mustacchi * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
144*35786f68SRobert Mustacchi * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
145*35786f68SRobert Mustacchi *
146*35786f68SRobert Mustacchi * Alternatively, you may choose to be licensed under the terms of the
147*35786f68SRobert Mustacchi * GNU General Public License ("GPL") version 2 as published by the Free
148*35786f68SRobert Mustacchi * Software Foundation.
149*35786f68SRobert Mustacchi *
150*35786f68SRobert Mustacchi *****************************************************************************/
151bc36eafdSMike Gerdts
152bc36eafdSMike Gerdts #include "aslcompiler.h"
153bc36eafdSMike Gerdts #include "aslcompiler.y.h"
154bc36eafdSMike Gerdts #include "acapps.h"
155bc36eafdSMike Gerdts
156bc36eafdSMike Gerdts #define _COMPONENT ACPI_COMPILER
157bc36eafdSMike Gerdts ACPI_MODULE_NAME ("asltree")
158bc36eafdSMike Gerdts
159bc36eafdSMike Gerdts
160bc36eafdSMike Gerdts /*******************************************************************************
161bc36eafdSMike Gerdts *
162*35786f68SRobert Mustacchi * FUNCTION: TrSetOpIntegerValue
163bc36eafdSMike Gerdts *
164*35786f68SRobert Mustacchi * PARAMETERS: ParseOpcode - New opcode to be assigned to the op
165*35786f68SRobert Mustacchi * Op - An existing parse op
166bc36eafdSMike Gerdts *
167*35786f68SRobert Mustacchi * RETURN: The updated op
168bc36eafdSMike Gerdts *
169*35786f68SRobert Mustacchi * DESCRIPTION: Used to set the integer value of a op,
170*35786f68SRobert Mustacchi * usually to a specific size (8, 16, 32, or 64 bits)
171bc36eafdSMike Gerdts *
172bc36eafdSMike Gerdts ******************************************************************************/
173bc36eafdSMike Gerdts
174bc36eafdSMike Gerdts ACPI_PARSE_OBJECT *
TrSetOpIntegerValue(UINT32 ParseOpcode,ACPI_PARSE_OBJECT * Op)175*35786f68SRobert Mustacchi TrSetOpIntegerValue (
176bc36eafdSMike Gerdts UINT32 ParseOpcode,
177bc36eafdSMike Gerdts ACPI_PARSE_OBJECT *Op)
178bc36eafdSMike Gerdts {
179bc36eafdSMike Gerdts
180bc36eafdSMike Gerdts if (!Op)
181bc36eafdSMike Gerdts {
182bc36eafdSMike Gerdts return (NULL);
183bc36eafdSMike Gerdts }
184bc36eafdSMike Gerdts
185bc36eafdSMike Gerdts DbgPrint (ASL_PARSE_OUTPUT,
186*35786f68SRobert Mustacchi "\nUpdateOp: Old - %s, New - %s\n",
187bc36eafdSMike Gerdts UtGetOpName (Op->Asl.ParseOpcode),
188bc36eafdSMike Gerdts UtGetOpName (ParseOpcode));
189bc36eafdSMike Gerdts
190bc36eafdSMike Gerdts /* Assign new opcode and name */
191bc36eafdSMike Gerdts
192bc36eafdSMike Gerdts if (Op->Asl.ParseOpcode == PARSEOP_ONES)
193bc36eafdSMike Gerdts {
194bc36eafdSMike Gerdts switch (ParseOpcode)
195bc36eafdSMike Gerdts {
196bc36eafdSMike Gerdts case PARSEOP_BYTECONST:
197bc36eafdSMike Gerdts
198bc36eafdSMike Gerdts Op->Asl.Value.Integer = ACPI_UINT8_MAX;
199bc36eafdSMike Gerdts break;
200bc36eafdSMike Gerdts
201bc36eafdSMike Gerdts case PARSEOP_WORDCONST:
202bc36eafdSMike Gerdts
203bc36eafdSMike Gerdts Op->Asl.Value.Integer = ACPI_UINT16_MAX;
204bc36eafdSMike Gerdts break;
205bc36eafdSMike Gerdts
206bc36eafdSMike Gerdts case PARSEOP_DWORDCONST:
207bc36eafdSMike Gerdts
208bc36eafdSMike Gerdts Op->Asl.Value.Integer = ACPI_UINT32_MAX;
209bc36eafdSMike Gerdts break;
210bc36eafdSMike Gerdts
211bc36eafdSMike Gerdts /* Don't need to do the QWORD case */
212bc36eafdSMike Gerdts
213bc36eafdSMike Gerdts default:
214bc36eafdSMike Gerdts
215bc36eafdSMike Gerdts /* Don't care about others */
216bc36eafdSMike Gerdts break;
217bc36eafdSMike Gerdts }
218bc36eafdSMike Gerdts }
219bc36eafdSMike Gerdts
220bc36eafdSMike Gerdts Op->Asl.ParseOpcode = (UINT16) ParseOpcode;
221bc36eafdSMike Gerdts UtSetParseOpName (Op);
222bc36eafdSMike Gerdts
223bc36eafdSMike Gerdts /*
224bc36eafdSMike Gerdts * For the BYTE, WORD, and DWORD constants, make sure that the integer
225bc36eafdSMike Gerdts * that was passed in will actually fit into the data type
226bc36eafdSMike Gerdts */
227bc36eafdSMike Gerdts switch (ParseOpcode)
228bc36eafdSMike Gerdts {
229bc36eafdSMike Gerdts case PARSEOP_BYTECONST:
230bc36eafdSMike Gerdts
231bc36eafdSMike Gerdts UtCheckIntegerRange (Op, 0x00, ACPI_UINT8_MAX);
232bc36eafdSMike Gerdts Op->Asl.Value.Integer &= ACPI_UINT8_MAX;
233bc36eafdSMike Gerdts break;
234bc36eafdSMike Gerdts
235bc36eafdSMike Gerdts case PARSEOP_WORDCONST:
236bc36eafdSMike Gerdts
237bc36eafdSMike Gerdts UtCheckIntegerRange (Op, 0x00, ACPI_UINT16_MAX);
238bc36eafdSMike Gerdts Op->Asl.Value.Integer &= ACPI_UINT16_MAX;
239bc36eafdSMike Gerdts break;
240bc36eafdSMike Gerdts
241bc36eafdSMike Gerdts case PARSEOP_DWORDCONST:
242bc36eafdSMike Gerdts
243bc36eafdSMike Gerdts UtCheckIntegerRange (Op, 0x00, ACPI_UINT32_MAX);
244bc36eafdSMike Gerdts Op->Asl.Value.Integer &= ACPI_UINT32_MAX;
245bc36eafdSMike Gerdts break;
246bc36eafdSMike Gerdts
247*35786f68SRobert Mustacchi default:
248bc36eafdSMike Gerdts
249*35786f68SRobert Mustacchi /* Don't care about others, don't need to check QWORD */
250bc36eafdSMike Gerdts
251*35786f68SRobert Mustacchi break;
252*35786f68SRobert Mustacchi }
253bc36eafdSMike Gerdts
254*35786f68SRobert Mustacchi /* Converter: if this is a method invocation, turn off capture comments */
255bc36eafdSMike Gerdts
256*35786f68SRobert Mustacchi if (AcpiGbl_CaptureComments &&
257*35786f68SRobert Mustacchi (ParseOpcode == PARSEOP_METHODCALL))
258*35786f68SRobert Mustacchi {
259*35786f68SRobert Mustacchi Gbl_CommentState.CaptureComments = FALSE;
260*35786f68SRobert Mustacchi }
261bc36eafdSMike Gerdts
262*35786f68SRobert Mustacchi return (Op);
263bc36eafdSMike Gerdts }
264bc36eafdSMike Gerdts
265bc36eafdSMike Gerdts
266bc36eafdSMike Gerdts /*******************************************************************************
267bc36eafdSMike Gerdts *
268*35786f68SRobert Mustacchi * FUNCTION: TrSetOpFlags
269bc36eafdSMike Gerdts *
270*35786f68SRobert Mustacchi * PARAMETERS: Op - An existing parse op
271*35786f68SRobert Mustacchi * Flags - New flags word
272bc36eafdSMike Gerdts *
273*35786f68SRobert Mustacchi * RETURN: The updated parser op
274bc36eafdSMike Gerdts *
275*35786f68SRobert Mustacchi * DESCRIPTION: Set bits in the op flags word. Will not clear bits, only set
276bc36eafdSMike Gerdts *
277bc36eafdSMike Gerdts ******************************************************************************/
278bc36eafdSMike Gerdts
279bc36eafdSMike Gerdts ACPI_PARSE_OBJECT *
TrSetOpFlags(ACPI_PARSE_OBJECT * Op,UINT32 Flags)280*35786f68SRobert Mustacchi TrSetOpFlags (
281*35786f68SRobert Mustacchi ACPI_PARSE_OBJECT *Op,
282*35786f68SRobert Mustacchi UINT32 Flags)
283bc36eafdSMike Gerdts {
284bc36eafdSMike Gerdts
285*35786f68SRobert Mustacchi if (!Op)
286*35786f68SRobert Mustacchi {
287*35786f68SRobert Mustacchi return (NULL);
288*35786f68SRobert Mustacchi }
289bc36eafdSMike Gerdts
290bc36eafdSMike Gerdts DbgPrint (ASL_PARSE_OUTPUT,
291*35786f68SRobert Mustacchi "\nSetOpFlags: %s Op %p, %8.8X", Op->Asl.ParseOpName, Op, Flags);
292bc36eafdSMike Gerdts
293*35786f68SRobert Mustacchi TrPrintOpFlags (Flags, ASL_PARSE_OUTPUT);
294*35786f68SRobert Mustacchi DbgPrint (ASL_PARSE_OUTPUT, "\n\n");
295*35786f68SRobert Mustacchi
296*35786f68SRobert Mustacchi Op->Asl.CompileFlags |= Flags;
297bc36eafdSMike Gerdts return (Op);
298bc36eafdSMike Gerdts }
299bc36eafdSMike Gerdts
300bc36eafdSMike Gerdts
301bc36eafdSMike Gerdts /*******************************************************************************
302bc36eafdSMike Gerdts *
303*35786f68SRobert Mustacchi * FUNCTION: TrSetOpAmlLength
304bc36eafdSMike Gerdts *
305*35786f68SRobert Mustacchi * PARAMETERS: Op - An existing parse op
306*35786f68SRobert Mustacchi * Length - AML Length
307bc36eafdSMike Gerdts *
308*35786f68SRobert Mustacchi * RETURN: The updated parser op
309bc36eafdSMike Gerdts *
310*35786f68SRobert Mustacchi * DESCRIPTION: Set the AML Length in a op. Used by the parser to indicate
311*35786f68SRobert Mustacchi * the presence of a op that must be reduced to a fixed length
312*35786f68SRobert Mustacchi * constant.
313bc36eafdSMike Gerdts *
314bc36eafdSMike Gerdts ******************************************************************************/
315bc36eafdSMike Gerdts
316bc36eafdSMike Gerdts ACPI_PARSE_OBJECT *
TrSetOpAmlLength(ACPI_PARSE_OBJECT * Op,UINT32 Length)317*35786f68SRobert Mustacchi TrSetOpAmlLength (
318*35786f68SRobert Mustacchi ACPI_PARSE_OBJECT *Op,
319*35786f68SRobert Mustacchi UINT32 Length)
320bc36eafdSMike Gerdts {
321bc36eafdSMike Gerdts
322bc36eafdSMike Gerdts DbgPrint (ASL_PARSE_OUTPUT,
323*35786f68SRobert Mustacchi "\nSetOpAmlLength: Op %p, %8.8X\n", Op, Length);
324*35786f68SRobert Mustacchi
325*35786f68SRobert Mustacchi if (!Op)
326*35786f68SRobert Mustacchi {
327*35786f68SRobert Mustacchi return (NULL);
328*35786f68SRobert Mustacchi }
329bc36eafdSMike Gerdts
330*35786f68SRobert Mustacchi Op->Asl.AmlLength = Length;
331bc36eafdSMike Gerdts return (Op);
332bc36eafdSMike Gerdts }
333bc36eafdSMike Gerdts
334bc36eafdSMike Gerdts
335bc36eafdSMike Gerdts /*******************************************************************************
336bc36eafdSMike Gerdts *
337*35786f68SRobert Mustacchi * FUNCTION: TrSetOpParent
338bc36eafdSMike Gerdts *
339*35786f68SRobert Mustacchi * PARAMETERS: Op - To be set to new parent
340*35786f68SRobert Mustacchi * ParentOp - The parent
341bc36eafdSMike Gerdts *
342*35786f68SRobert Mustacchi * RETURN: None, sets Op parent directly
343bc36eafdSMike Gerdts *
344*35786f68SRobert Mustacchi * DESCRIPTION: Change the parent of a parse op.
345bc36eafdSMike Gerdts *
346bc36eafdSMike Gerdts ******************************************************************************/
347bc36eafdSMike Gerdts
348*35786f68SRobert Mustacchi void
TrSetOpParent(ACPI_PARSE_OBJECT * Op,ACPI_PARSE_OBJECT * ParentOp)349*35786f68SRobert Mustacchi TrSetOpParent (
350*35786f68SRobert Mustacchi ACPI_PARSE_OBJECT *Op,
351*35786f68SRobert Mustacchi ACPI_PARSE_OBJECT *ParentOp)
352bc36eafdSMike Gerdts {
353bc36eafdSMike Gerdts
354*35786f68SRobert Mustacchi Op->Asl.Parent = ParentOp;
355bc36eafdSMike Gerdts }
356bc36eafdSMike Gerdts
357bc36eafdSMike Gerdts
358bc36eafdSMike Gerdts /*******************************************************************************
359bc36eafdSMike Gerdts *
360*35786f68SRobert Mustacchi * FUNCTION: TrSetOpCurrentFilename
361bc36eafdSMike Gerdts *
362*35786f68SRobert Mustacchi * PARAMETERS: Op - An existing parse op
363bc36eafdSMike Gerdts *
364*35786f68SRobert Mustacchi * RETURN: None
365bc36eafdSMike Gerdts *
366*35786f68SRobert Mustacchi * DESCRIPTION: Save the include file filename. Used for debug output only.
367bc36eafdSMike Gerdts *
368bc36eafdSMike Gerdts ******************************************************************************/
369bc36eafdSMike Gerdts
370*35786f68SRobert Mustacchi void
TrSetOpCurrentFilename(ACPI_PARSE_OBJECT * Op)371*35786f68SRobert Mustacchi TrSetOpCurrentFilename (
372*35786f68SRobert Mustacchi ACPI_PARSE_OBJECT *Op)
373bc36eafdSMike Gerdts {
374bc36eafdSMike Gerdts
375*35786f68SRobert Mustacchi Op->Asl.Filename = Gbl_PreviousIncludeFilename;
376bc36eafdSMike Gerdts }
377bc36eafdSMike Gerdts
378bc36eafdSMike Gerdts
379bc36eafdSMike Gerdts /*******************************************************************************
380bc36eafdSMike Gerdts *
381*35786f68SRobert Mustacchi * FUNCTION: TrSetOpIntegerWidth
382bc36eafdSMike Gerdts *
383*35786f68SRobert Mustacchi * PARAMETERS: Op - An existing parse op
384bc36eafdSMike Gerdts *
385*35786f68SRobert Mustacchi * RETURN: None
386bc36eafdSMike Gerdts *
387*35786f68SRobert Mustacchi * DESCRIPTION:
388bc36eafdSMike Gerdts *
389bc36eafdSMike Gerdts ******************************************************************************/
390bc36eafdSMike Gerdts
391*35786f68SRobert Mustacchi void
TrSetOpIntegerWidth(ACPI_PARSE_OBJECT * TableSignatureOp,ACPI_PARSE_OBJECT * RevisionOp)392*35786f68SRobert Mustacchi TrSetOpIntegerWidth (
393*35786f68SRobert Mustacchi ACPI_PARSE_OBJECT *TableSignatureOp,
394*35786f68SRobert Mustacchi ACPI_PARSE_OBJECT *RevisionOp)
395bc36eafdSMike Gerdts {
396bc36eafdSMike Gerdts
397*35786f68SRobert Mustacchi /* TBD: Check table sig? (DSDT vs. SSDT) */
398bc36eafdSMike Gerdts
399*35786f68SRobert Mustacchi /* Handle command-line version override */
400bc36eafdSMike Gerdts
401*35786f68SRobert Mustacchi if (Gbl_RevisionOverride)
402bc36eafdSMike Gerdts {
403*35786f68SRobert Mustacchi AcpiUtSetIntegerWidth (Gbl_RevisionOverride);
404*35786f68SRobert Mustacchi }
405*35786f68SRobert Mustacchi else
406*35786f68SRobert Mustacchi {
407*35786f68SRobert Mustacchi AcpiUtSetIntegerWidth ((UINT8) RevisionOp->Asl.Value.Integer);
408bc36eafdSMike Gerdts }
409bc36eafdSMike Gerdts }
410bc36eafdSMike Gerdts
411bc36eafdSMike Gerdts
412bc36eafdSMike Gerdts /*******************************************************************************
413bc36eafdSMike Gerdts *
414*35786f68SRobert Mustacchi * FUNCTION: TrSetOpEndLineNumber
415bc36eafdSMike Gerdts *
416*35786f68SRobert Mustacchi * PARAMETERS: Op - An existing parse op
417bc36eafdSMike Gerdts *
418*35786f68SRobert Mustacchi * RETURN: None.
419bc36eafdSMike Gerdts *
420*35786f68SRobert Mustacchi * DESCRIPTION: Set the ending line numbers (file line and logical line) of a
421*35786f68SRobert Mustacchi * parse op to the current line numbers.
422bc36eafdSMike Gerdts *
423bc36eafdSMike Gerdts ******************************************************************************/
424bc36eafdSMike Gerdts
425*35786f68SRobert Mustacchi void
TrSetOpEndLineNumber(ACPI_PARSE_OBJECT * Op)426*35786f68SRobert Mustacchi TrSetOpEndLineNumber (
427*35786f68SRobert Mustacchi ACPI_PARSE_OBJECT *Op)
428bc36eafdSMike Gerdts {
429bc36eafdSMike Gerdts
430*35786f68SRobert Mustacchi /* If the end line # is already set, just return */
431bc36eafdSMike Gerdts
432*35786f68SRobert Mustacchi if (Op->Asl.EndLine)
433bc36eafdSMike Gerdts {
434*35786f68SRobert Mustacchi return;
435bc36eafdSMike Gerdts }
436bc36eafdSMike Gerdts
437*35786f68SRobert Mustacchi Op->Asl.EndLine = Gbl_CurrentLineNumber;
438*35786f68SRobert Mustacchi Op->Asl.EndLogicalLine = Gbl_LogicalLineNumber;
439bc36eafdSMike Gerdts }
440bc36eafdSMike Gerdts
441bc36eafdSMike Gerdts
442bc36eafdSMike Gerdts /*******************************************************************************
443bc36eafdSMike Gerdts *
444*35786f68SRobert Mustacchi * FUNCTION: TrLinkOpChildren
445bc36eafdSMike Gerdts *
446*35786f68SRobert Mustacchi * PARAMETERS: Op - An existing parse op
447*35786f68SRobert Mustacchi * NumChildren - Number of children to follow
448*35786f68SRobert Mustacchi * ... - A list of child ops to link to the new
449*35786f68SRobert Mustacchi * op. NumChildren long.
450bc36eafdSMike Gerdts *
451*35786f68SRobert Mustacchi * RETURN: The updated (linked) op
452bc36eafdSMike Gerdts *
453*35786f68SRobert Mustacchi * DESCRIPTION: Link a group of ops to an existing parse op
454bc36eafdSMike Gerdts *
455bc36eafdSMike Gerdts ******************************************************************************/
456bc36eafdSMike Gerdts
457bc36eafdSMike Gerdts ACPI_PARSE_OBJECT *
TrLinkOpChildren(ACPI_PARSE_OBJECT * Op,UINT32 NumChildren,...)458*35786f68SRobert Mustacchi TrLinkOpChildren (
459bc36eafdSMike Gerdts ACPI_PARSE_OBJECT *Op,
460bc36eafdSMike Gerdts UINT32 NumChildren,
461bc36eafdSMike Gerdts ...)
462bc36eafdSMike Gerdts {
463bc36eafdSMike Gerdts ACPI_PARSE_OBJECT *Child;
464bc36eafdSMike Gerdts ACPI_PARSE_OBJECT *PrevChild;
465bc36eafdSMike Gerdts va_list ap;
466bc36eafdSMike Gerdts UINT32 i;
467bc36eafdSMike Gerdts BOOLEAN FirstChild;
468bc36eafdSMike Gerdts
469bc36eafdSMike Gerdts
470bc36eafdSMike Gerdts va_start (ap, NumChildren);
471bc36eafdSMike Gerdts
472*35786f68SRobert Mustacchi TrSetOpEndLineNumber (Op);
473bc36eafdSMike Gerdts
474bc36eafdSMike Gerdts DbgPrint (ASL_PARSE_OUTPUT,
475bc36eafdSMike Gerdts "\nLinkChildren Line [%u to %u] NewParent %p Child %u Op %s ",
476bc36eafdSMike Gerdts Op->Asl.LineNumber, Op->Asl.EndLine,
477bc36eafdSMike Gerdts Op, NumChildren, UtGetOpName(Op->Asl.ParseOpcode));
478bc36eafdSMike Gerdts
479bc36eafdSMike Gerdts switch (Op->Asl.ParseOpcode)
480bc36eafdSMike Gerdts {
481bc36eafdSMike Gerdts case PARSEOP_ASL_CODE:
482bc36eafdSMike Gerdts
483bc36eafdSMike Gerdts Gbl_ParseTreeRoot = Op;
484bc36eafdSMike Gerdts Op->Asl.ParseOpcode = PARSEOP_DEFAULT_ARG;
485bc36eafdSMike Gerdts DbgPrint (ASL_PARSE_OUTPUT, "ASLCODE (Tree Completed)->");
486bc36eafdSMike Gerdts break;
487bc36eafdSMike Gerdts
488bc36eafdSMike Gerdts case PARSEOP_DEFINITION_BLOCK:
489bc36eafdSMike Gerdts
490bc36eafdSMike Gerdts DbgPrint (ASL_PARSE_OUTPUT, "DEFINITION_BLOCK (Tree Completed)->");
491bc36eafdSMike Gerdts break;
492bc36eafdSMike Gerdts
493bc36eafdSMike Gerdts case PARSEOP_OPERATIONREGION:
494bc36eafdSMike Gerdts
495bc36eafdSMike Gerdts DbgPrint (ASL_PARSE_OUTPUT, "OPREGION->");
496bc36eafdSMike Gerdts break;
497bc36eafdSMike Gerdts
498bc36eafdSMike Gerdts case PARSEOP_OR:
499bc36eafdSMike Gerdts
500bc36eafdSMike Gerdts DbgPrint (ASL_PARSE_OUTPUT, "OR->");
501bc36eafdSMike Gerdts break;
502bc36eafdSMike Gerdts
503bc36eafdSMike Gerdts default:
504bc36eafdSMike Gerdts
505bc36eafdSMike Gerdts /* Nothing to do for other opcodes */
506bc36eafdSMike Gerdts
507bc36eafdSMike Gerdts break;
508bc36eafdSMike Gerdts }
509bc36eafdSMike Gerdts
510*35786f68SRobert Mustacchi /* The following is for capturing comments */
511*35786f68SRobert Mustacchi
512*35786f68SRobert Mustacchi if (AcpiGbl_CaptureComments)
513*35786f68SRobert Mustacchi {
514*35786f68SRobert Mustacchi /*
515*35786f68SRobert Mustacchi * If there are "regular comments" detected at this point,
516*35786f68SRobert Mustacchi * then is an endBlk comment. Categorize it as so and distribute
517*35786f68SRobert Mustacchi * all regular comments to this parse op.
518*35786f68SRobert Mustacchi */
519*35786f68SRobert Mustacchi if (Gbl_CommentListHead)
520*35786f68SRobert Mustacchi {
521*35786f68SRobert Mustacchi Op->Asl.EndBlkComment = Gbl_CommentListHead;
522*35786f68SRobert Mustacchi CvDbgPrint ("EndBlk Comment for %s: %s",
523*35786f68SRobert Mustacchi Op->Asl.ParseOpName, Gbl_CommentListHead->Comment);
524*35786f68SRobert Mustacchi Gbl_CommentListHead = NULL;
525*35786f68SRobert Mustacchi Gbl_CommentListTail = NULL;
526*35786f68SRobert Mustacchi }
527*35786f68SRobert Mustacchi }
528*35786f68SRobert Mustacchi
529*35786f68SRobert Mustacchi /* Link the new op to it's children */
530bc36eafdSMike Gerdts
531bc36eafdSMike Gerdts PrevChild = NULL;
532bc36eafdSMike Gerdts FirstChild = TRUE;
533bc36eafdSMike Gerdts for (i = 0; i < NumChildren; i++)
534bc36eafdSMike Gerdts {
535bc36eafdSMike Gerdts Child = va_arg (ap, ACPI_PARSE_OBJECT *);
536bc36eafdSMike Gerdts
537bc36eafdSMike Gerdts if ((Child == PrevChild) && (Child != NULL))
538bc36eafdSMike Gerdts {
539bc36eafdSMike Gerdts AslError (ASL_WARNING, ASL_MSG_COMPILER_INTERNAL, Child,
540*35786f68SRobert Mustacchi "Child op list invalid");
541bc36eafdSMike Gerdts va_end(ap);
542bc36eafdSMike Gerdts return (Op);
543bc36eafdSMike Gerdts }
544bc36eafdSMike Gerdts
545bc36eafdSMike Gerdts DbgPrint (ASL_PARSE_OUTPUT, "%p, ", Child);
546bc36eafdSMike Gerdts
547bc36eafdSMike Gerdts /*
548bc36eafdSMike Gerdts * If child is NULL, this means that an optional argument
549bc36eafdSMike Gerdts * was omitted. We must create a placeholder with a special
550bc36eafdSMike Gerdts * opcode (DEFAULT_ARG) so that the code generator will know
551bc36eafdSMike Gerdts * that it must emit the correct default for this argument
552bc36eafdSMike Gerdts */
553bc36eafdSMike Gerdts if (!Child)
554bc36eafdSMike Gerdts {
555*35786f68SRobert Mustacchi Child = TrAllocateOp (PARSEOP_DEFAULT_ARG);
556bc36eafdSMike Gerdts }
557bc36eafdSMike Gerdts
558bc36eafdSMike Gerdts /* Link first child to parent */
559bc36eafdSMike Gerdts
560bc36eafdSMike Gerdts if (FirstChild)
561bc36eafdSMike Gerdts {
562bc36eafdSMike Gerdts FirstChild = FALSE;
563bc36eafdSMike Gerdts Op->Asl.Child = Child;
564bc36eafdSMike Gerdts }
565bc36eafdSMike Gerdts
566bc36eafdSMike Gerdts /* Point all children to parent */
567bc36eafdSMike Gerdts
568bc36eafdSMike Gerdts Child->Asl.Parent = Op;
569bc36eafdSMike Gerdts
570bc36eafdSMike Gerdts /* Link children in a peer list */
571bc36eafdSMike Gerdts
572bc36eafdSMike Gerdts if (PrevChild)
573bc36eafdSMike Gerdts {
574bc36eafdSMike Gerdts PrevChild->Asl.Next = Child;
575*35786f68SRobert Mustacchi }
576bc36eafdSMike Gerdts
577bc36eafdSMike Gerdts /*
578*35786f68SRobert Mustacchi * This child might be a list, point all ops in the list
579bc36eafdSMike Gerdts * to the same parent
580bc36eafdSMike Gerdts */
581bc36eafdSMike Gerdts while (Child->Asl.Next)
582bc36eafdSMike Gerdts {
583bc36eafdSMike Gerdts Child = Child->Asl.Next;
584bc36eafdSMike Gerdts Child->Asl.Parent = Op;
585bc36eafdSMike Gerdts }
586bc36eafdSMike Gerdts
587bc36eafdSMike Gerdts PrevChild = Child;
588bc36eafdSMike Gerdts }
589bc36eafdSMike Gerdts
590bc36eafdSMike Gerdts va_end(ap);
591bc36eafdSMike Gerdts DbgPrint (ASL_PARSE_OUTPUT, "\n\n");
592*35786f68SRobert Mustacchi
593*35786f68SRobert Mustacchi if (AcpiGbl_CaptureComments)
594*35786f68SRobert Mustacchi {
595*35786f68SRobert Mustacchi Gbl_CommentState.LatestParseOp = Op;
596*35786f68SRobert Mustacchi CvDbgPrint ("TrLinkOpChildren=====Set latest parse op to this op.\n");
597*35786f68SRobert Mustacchi }
598*35786f68SRobert Mustacchi
599bc36eafdSMike Gerdts return (Op);
600bc36eafdSMike Gerdts }
601bc36eafdSMike Gerdts
602bc36eafdSMike Gerdts
603bc36eafdSMike Gerdts /*******************************************************************************
604bc36eafdSMike Gerdts *
605*35786f68SRobert Mustacchi * FUNCTION: TrLinkPeerOp
606bc36eafdSMike Gerdts *
607bc36eafdSMike Gerdts * PARAMETERS: Op1 - First peer
608bc36eafdSMike Gerdts * Op2 - Second peer
609bc36eafdSMike Gerdts *
610*35786f68SRobert Mustacchi * RETURN: Op1 or the non-null op.
611bc36eafdSMike Gerdts *
612*35786f68SRobert Mustacchi * DESCRIPTION: Link two ops as peers. Handles cases where one peer is null.
613bc36eafdSMike Gerdts *
614bc36eafdSMike Gerdts ******************************************************************************/
615bc36eafdSMike Gerdts
616bc36eafdSMike Gerdts ACPI_PARSE_OBJECT *
TrLinkPeerOp(ACPI_PARSE_OBJECT * Op1,ACPI_PARSE_OBJECT * Op2)617*35786f68SRobert Mustacchi TrLinkPeerOp (
618bc36eafdSMike Gerdts ACPI_PARSE_OBJECT *Op1,
619bc36eafdSMike Gerdts ACPI_PARSE_OBJECT *Op2)
620bc36eafdSMike Gerdts {
621bc36eafdSMike Gerdts ACPI_PARSE_OBJECT *Next;
622bc36eafdSMike Gerdts
623bc36eafdSMike Gerdts
624bc36eafdSMike Gerdts DbgPrint (ASL_PARSE_OUTPUT,
625*35786f68SRobert Mustacchi "\nLinkPeerOp: 1=%p (%s), 2=%p (%s)\n",
626bc36eafdSMike Gerdts Op1, Op1 ? UtGetOpName(Op1->Asl.ParseOpcode) : NULL,
627bc36eafdSMike Gerdts Op2, Op2 ? UtGetOpName(Op2->Asl.ParseOpcode) : NULL);
628bc36eafdSMike Gerdts
629bc36eafdSMike Gerdts
630bc36eafdSMike Gerdts if ((!Op1) && (!Op2))
631bc36eafdSMike Gerdts {
632*35786f68SRobert Mustacchi DbgPrint (ASL_PARSE_OUTPUT, "\nTwo Null ops!\n");
633bc36eafdSMike Gerdts return (Op1);
634bc36eafdSMike Gerdts }
635bc36eafdSMike Gerdts
636*35786f68SRobert Mustacchi /* If one of the ops is null, just return the non-null op */
637bc36eafdSMike Gerdts
638bc36eafdSMike Gerdts if (!Op2)
639bc36eafdSMike Gerdts {
640bc36eafdSMike Gerdts return (Op1);
641bc36eafdSMike Gerdts }
642bc36eafdSMike Gerdts
643bc36eafdSMike Gerdts if (!Op1)
644bc36eafdSMike Gerdts {
645bc36eafdSMike Gerdts return (Op2);
646bc36eafdSMike Gerdts }
647bc36eafdSMike Gerdts
648bc36eafdSMike Gerdts if (Op1 == Op2)
649bc36eafdSMike Gerdts {
650bc36eafdSMike Gerdts DbgPrint (ASL_DEBUG_OUTPUT,
651*35786f68SRobert Mustacchi "\n************* Internal error, linking op to itself %p\n",
652bc36eafdSMike Gerdts Op1);
653bc36eafdSMike Gerdts AslError (ASL_WARNING, ASL_MSG_COMPILER_INTERNAL, Op1,
654*35786f68SRobert Mustacchi "Linking op to itself");
655bc36eafdSMike Gerdts return (Op1);
656bc36eafdSMike Gerdts }
657bc36eafdSMike Gerdts
658bc36eafdSMike Gerdts Op1->Asl.Parent = Op2->Asl.Parent;
659bc36eafdSMike Gerdts
660bc36eafdSMike Gerdts /*
661bc36eafdSMike Gerdts * Op 1 may already have a peer list (such as an IF/ELSE pair),
662bc36eafdSMike Gerdts * so we must walk to the end of the list and attach the new
663bc36eafdSMike Gerdts * peer at the end
664bc36eafdSMike Gerdts */
665bc36eafdSMike Gerdts Next = Op1;
666bc36eafdSMike Gerdts while (Next->Asl.Next)
667bc36eafdSMike Gerdts {
668bc36eafdSMike Gerdts Next = Next->Asl.Next;
669bc36eafdSMike Gerdts }
670bc36eafdSMike Gerdts
671bc36eafdSMike Gerdts Next->Asl.Next = Op2;
672bc36eafdSMike Gerdts return (Op1);
673bc36eafdSMike Gerdts }
674bc36eafdSMike Gerdts
675bc36eafdSMike Gerdts
676bc36eafdSMike Gerdts /*******************************************************************************
677bc36eafdSMike Gerdts *
678*35786f68SRobert Mustacchi * FUNCTION: TrLinkPeerOps
679bc36eafdSMike Gerdts *
680*35786f68SRobert Mustacchi * PARAMETERS: NumPeers - The number of ops in the list to follow
681*35786f68SRobert Mustacchi * ... - A list of ops to link together as peers
682bc36eafdSMike Gerdts *
683*35786f68SRobert Mustacchi * RETURN: The first op in the list (head of the peer list)
684bc36eafdSMike Gerdts *
685*35786f68SRobert Mustacchi * DESCRIPTION: Link together an arbitrary number of peer ops.
686bc36eafdSMike Gerdts *
687bc36eafdSMike Gerdts ******************************************************************************/
688bc36eafdSMike Gerdts
689bc36eafdSMike Gerdts ACPI_PARSE_OBJECT *
TrLinkPeerOps(UINT32 NumPeers,...)690*35786f68SRobert Mustacchi TrLinkPeerOps (
691bc36eafdSMike Gerdts UINT32 NumPeers,
692bc36eafdSMike Gerdts ...)
693bc36eafdSMike Gerdts {
694bc36eafdSMike Gerdts ACPI_PARSE_OBJECT *This;
695bc36eafdSMike Gerdts ACPI_PARSE_OBJECT *Next;
696bc36eafdSMike Gerdts va_list ap;
697bc36eafdSMike Gerdts UINT32 i;
698bc36eafdSMike Gerdts ACPI_PARSE_OBJECT *Start;
699bc36eafdSMike Gerdts
700bc36eafdSMike Gerdts
701bc36eafdSMike Gerdts DbgPrint (ASL_PARSE_OUTPUT,
702*35786f68SRobert Mustacchi "\nLinkPeerOps: (%u) ", NumPeers);
703bc36eafdSMike Gerdts
704bc36eafdSMike Gerdts va_start (ap, NumPeers);
705bc36eafdSMike Gerdts This = va_arg (ap, ACPI_PARSE_OBJECT *);
706bc36eafdSMike Gerdts Start = This;
707bc36eafdSMike Gerdts
708bc36eafdSMike Gerdts /*
709bc36eafdSMike Gerdts * Link all peers
710bc36eafdSMike Gerdts */
711bc36eafdSMike Gerdts for (i = 0; i < (NumPeers -1); i++)
712bc36eafdSMike Gerdts {
713bc36eafdSMike Gerdts DbgPrint (ASL_PARSE_OUTPUT, "%u=%p ", (i+1), This);
714bc36eafdSMike Gerdts
715bc36eafdSMike Gerdts while (This->Asl.Next)
716bc36eafdSMike Gerdts {
717bc36eafdSMike Gerdts This = This->Asl.Next;
718bc36eafdSMike Gerdts }
719bc36eafdSMike Gerdts
720*35786f68SRobert Mustacchi /* Get another peer op */
721bc36eafdSMike Gerdts
722bc36eafdSMike Gerdts Next = va_arg (ap, ACPI_PARSE_OBJECT *);
723bc36eafdSMike Gerdts if (!Next)
724bc36eafdSMike Gerdts {
725*35786f68SRobert Mustacchi Next = TrAllocateOp (PARSEOP_DEFAULT_ARG);
726bc36eafdSMike Gerdts }
727bc36eafdSMike Gerdts
728*35786f68SRobert Mustacchi /* link new op to the current op */
729bc36eafdSMike Gerdts
730bc36eafdSMike Gerdts This->Asl.Next = Next;
731bc36eafdSMike Gerdts This = Next;
732bc36eafdSMike Gerdts }
733bc36eafdSMike Gerdts
734*35786f68SRobert Mustacchi va_end (ap);
735bc36eafdSMike Gerdts DbgPrint (ASL_PARSE_OUTPUT,"\n");
736bc36eafdSMike Gerdts return (Start);
737bc36eafdSMike Gerdts }
738bc36eafdSMike Gerdts
739bc36eafdSMike Gerdts
740bc36eafdSMike Gerdts /*******************************************************************************
741bc36eafdSMike Gerdts *
742*35786f68SRobert Mustacchi * FUNCTION: TrLinkChildOp
743bc36eafdSMike Gerdts *
744*35786f68SRobert Mustacchi * PARAMETERS: Op1 - Parent op
745bc36eafdSMike Gerdts * Op2 - Op to become a child
746bc36eafdSMike Gerdts *
747*35786f68SRobert Mustacchi * RETURN: The parent op
748bc36eafdSMike Gerdts *
749*35786f68SRobert Mustacchi * DESCRIPTION: Link two ops together as a parent and child
750bc36eafdSMike Gerdts *
751bc36eafdSMike Gerdts ******************************************************************************/
752bc36eafdSMike Gerdts
753bc36eafdSMike Gerdts ACPI_PARSE_OBJECT *
TrLinkChildOp(ACPI_PARSE_OBJECT * Op1,ACPI_PARSE_OBJECT * Op2)754*35786f68SRobert Mustacchi TrLinkChildOp (
755bc36eafdSMike Gerdts ACPI_PARSE_OBJECT *Op1,
756bc36eafdSMike Gerdts ACPI_PARSE_OBJECT *Op2)
757bc36eafdSMike Gerdts {
758bc36eafdSMike Gerdts ACPI_PARSE_OBJECT *Next;
759bc36eafdSMike Gerdts
760bc36eafdSMike Gerdts
761bc36eafdSMike Gerdts DbgPrint (ASL_PARSE_OUTPUT,
762*35786f68SRobert Mustacchi "\nLinkChildOp: Parent=%p (%s), Child=%p (%s)\n",
763bc36eafdSMike Gerdts Op1, Op1 ? UtGetOpName(Op1->Asl.ParseOpcode): NULL,
764bc36eafdSMike Gerdts Op2, Op2 ? UtGetOpName(Op2->Asl.ParseOpcode): NULL);
765bc36eafdSMike Gerdts
766*35786f68SRobert Mustacchi /*
767*35786f68SRobert Mustacchi * Converter: if TrLinkChildOp is called to link a method call,
768*35786f68SRobert Mustacchi * turn on capture comments as it signifies that we are done parsing
769*35786f68SRobert Mustacchi * a method call.
770*35786f68SRobert Mustacchi */
771*35786f68SRobert Mustacchi if (AcpiGbl_CaptureComments && Op1)
772*35786f68SRobert Mustacchi {
773*35786f68SRobert Mustacchi if (Op1->Asl.ParseOpcode == PARSEOP_METHODCALL)
774*35786f68SRobert Mustacchi {
775*35786f68SRobert Mustacchi Gbl_CommentState.CaptureComments = TRUE;
776*35786f68SRobert Mustacchi }
777*35786f68SRobert Mustacchi Gbl_CommentState.LatestParseOp = Op1;
778*35786f68SRobert Mustacchi }
779*35786f68SRobert Mustacchi
780bc36eafdSMike Gerdts if (!Op1 || !Op2)
781bc36eafdSMike Gerdts {
782bc36eafdSMike Gerdts return (Op1);
783bc36eafdSMike Gerdts }
784bc36eafdSMike Gerdts
785bc36eafdSMike Gerdts Op1->Asl.Child = Op2;
786bc36eafdSMike Gerdts
787bc36eafdSMike Gerdts /* Set the child and all peers of the child to point to the parent */
788bc36eafdSMike Gerdts
789bc36eafdSMike Gerdts Next = Op2;
790bc36eafdSMike Gerdts while (Next)
791bc36eafdSMike Gerdts {
792bc36eafdSMike Gerdts Next->Asl.Parent = Op1;
793bc36eafdSMike Gerdts Next = Next->Asl.Next;
794bc36eafdSMike Gerdts }
795bc36eafdSMike Gerdts
796bc36eafdSMike Gerdts return (Op1);
797bc36eafdSMike Gerdts }
798bc36eafdSMike Gerdts
799bc36eafdSMike Gerdts
800bc36eafdSMike Gerdts /*******************************************************************************
801bc36eafdSMike Gerdts *
802bc36eafdSMike Gerdts * FUNCTION: TrWalkParseTree
803bc36eafdSMike Gerdts *
804*35786f68SRobert Mustacchi * PARAMETERS: Op - Walk starting point
805*35786f68SRobert Mustacchi * Visitation - Type of walk
806bc36eafdSMike Gerdts * DescendingCallback - Called during tree descent
807bc36eafdSMike Gerdts * AscendingCallback - Called during tree ascent
808bc36eafdSMike Gerdts * Context - To be passed to the callbacks
809bc36eafdSMike Gerdts *
810bc36eafdSMike Gerdts * RETURN: Status from callback(s)
811bc36eafdSMike Gerdts *
812bc36eafdSMike Gerdts * DESCRIPTION: Walk the entire parse tree.
813bc36eafdSMike Gerdts *
814bc36eafdSMike Gerdts ******************************************************************************/
815bc36eafdSMike Gerdts
816bc36eafdSMike Gerdts ACPI_STATUS
TrWalkParseTree(ACPI_PARSE_OBJECT * Op,UINT32 Visitation,ASL_WALK_CALLBACK DescendingCallback,ASL_WALK_CALLBACK AscendingCallback,void * Context)817bc36eafdSMike Gerdts TrWalkParseTree (
818bc36eafdSMike Gerdts ACPI_PARSE_OBJECT *Op,
819bc36eafdSMike Gerdts UINT32 Visitation,
820bc36eafdSMike Gerdts ASL_WALK_CALLBACK DescendingCallback,
821bc36eafdSMike Gerdts ASL_WALK_CALLBACK AscendingCallback,
822bc36eafdSMike Gerdts void *Context)
823bc36eafdSMike Gerdts {
824bc36eafdSMike Gerdts UINT32 Level;
825*35786f68SRobert Mustacchi BOOLEAN OpPreviouslyVisited;
826bc36eafdSMike Gerdts ACPI_PARSE_OBJECT *StartOp = Op;
827bc36eafdSMike Gerdts ACPI_STATUS Status;
828bc36eafdSMike Gerdts
829bc36eafdSMike Gerdts
830bc36eafdSMike Gerdts if (!Gbl_ParseTreeRoot)
831bc36eafdSMike Gerdts {
832bc36eafdSMike Gerdts return (AE_OK);
833bc36eafdSMike Gerdts }
834bc36eafdSMike Gerdts
835bc36eafdSMike Gerdts Level = 0;
836*35786f68SRobert Mustacchi OpPreviouslyVisited = FALSE;
837bc36eafdSMike Gerdts
838bc36eafdSMike Gerdts switch (Visitation)
839bc36eafdSMike Gerdts {
840bc36eafdSMike Gerdts case ASL_WALK_VISIT_DOWNWARD:
841bc36eafdSMike Gerdts
842bc36eafdSMike Gerdts while (Op)
843bc36eafdSMike Gerdts {
844*35786f68SRobert Mustacchi if (!OpPreviouslyVisited)
845bc36eafdSMike Gerdts {
846*35786f68SRobert Mustacchi /* Let the callback process the op. */
847bc36eafdSMike Gerdts
848bc36eafdSMike Gerdts Status = DescendingCallback (Op, Level, Context);
849bc36eafdSMike Gerdts if (ACPI_SUCCESS (Status))
850bc36eafdSMike Gerdts {
851bc36eafdSMike Gerdts /* Visit children first, once */
852bc36eafdSMike Gerdts
853bc36eafdSMike Gerdts if (Op->Asl.Child)
854bc36eafdSMike Gerdts {
855bc36eafdSMike Gerdts Level++;
856bc36eafdSMike Gerdts Op = Op->Asl.Child;
857bc36eafdSMike Gerdts continue;
858bc36eafdSMike Gerdts }
859bc36eafdSMike Gerdts }
860bc36eafdSMike Gerdts else if (Status != AE_CTRL_DEPTH)
861bc36eafdSMike Gerdts {
862bc36eafdSMike Gerdts /* Exit immediately on any error */
863bc36eafdSMike Gerdts
864bc36eafdSMike Gerdts return (Status);
865bc36eafdSMike Gerdts }
866bc36eafdSMike Gerdts }
867bc36eafdSMike Gerdts
868bc36eafdSMike Gerdts /* Terminate walk at start op */
869bc36eafdSMike Gerdts
870bc36eafdSMike Gerdts if (Op == StartOp)
871bc36eafdSMike Gerdts {
872bc36eafdSMike Gerdts break;
873bc36eafdSMike Gerdts }
874bc36eafdSMike Gerdts
875bc36eafdSMike Gerdts /* No more children, visit peers */
876bc36eafdSMike Gerdts
877bc36eafdSMike Gerdts if (Op->Asl.Next)
878bc36eafdSMike Gerdts {
879bc36eafdSMike Gerdts Op = Op->Asl.Next;
880*35786f68SRobert Mustacchi OpPreviouslyVisited = FALSE;
881bc36eafdSMike Gerdts }
882bc36eafdSMike Gerdts else
883bc36eafdSMike Gerdts {
884bc36eafdSMike Gerdts /* No children or peers, re-visit parent */
885bc36eafdSMike Gerdts
886bc36eafdSMike Gerdts if (Level != 0 )
887bc36eafdSMike Gerdts {
888bc36eafdSMike Gerdts Level--;
889bc36eafdSMike Gerdts }
890bc36eafdSMike Gerdts Op = Op->Asl.Parent;
891*35786f68SRobert Mustacchi OpPreviouslyVisited = TRUE;
892bc36eafdSMike Gerdts }
893bc36eafdSMike Gerdts }
894bc36eafdSMike Gerdts break;
895bc36eafdSMike Gerdts
896bc36eafdSMike Gerdts case ASL_WALK_VISIT_UPWARD:
897bc36eafdSMike Gerdts
898bc36eafdSMike Gerdts while (Op)
899bc36eafdSMike Gerdts {
900*35786f68SRobert Mustacchi /* Visit leaf op (no children) or parent op on return trip */
901bc36eafdSMike Gerdts
902bc36eafdSMike Gerdts if ((!Op->Asl.Child) ||
903*35786f68SRobert Mustacchi (OpPreviouslyVisited))
904bc36eafdSMike Gerdts {
905*35786f68SRobert Mustacchi /* Let the callback process the op. */
906bc36eafdSMike Gerdts
907bc36eafdSMike Gerdts Status = AscendingCallback (Op, Level, Context);
908bc36eafdSMike Gerdts if (ACPI_FAILURE (Status))
909bc36eafdSMike Gerdts {
910bc36eafdSMike Gerdts return (Status);
911bc36eafdSMike Gerdts }
912bc36eafdSMike Gerdts }
913bc36eafdSMike Gerdts else
914bc36eafdSMike Gerdts {
915bc36eafdSMike Gerdts /* Visit children first, once */
916bc36eafdSMike Gerdts
917bc36eafdSMike Gerdts Level++;
918bc36eafdSMike Gerdts Op = Op->Asl.Child;
919bc36eafdSMike Gerdts continue;
920bc36eafdSMike Gerdts }
921bc36eafdSMike Gerdts
922bc36eafdSMike Gerdts /* Terminate walk at start op */
923bc36eafdSMike Gerdts
924bc36eafdSMike Gerdts if (Op == StartOp)
925bc36eafdSMike Gerdts {
926bc36eafdSMike Gerdts break;
927bc36eafdSMike Gerdts }
928bc36eafdSMike Gerdts
929bc36eafdSMike Gerdts /* No more children, visit peers */
930bc36eafdSMike Gerdts
931bc36eafdSMike Gerdts if (Op->Asl.Next)
932bc36eafdSMike Gerdts {
933bc36eafdSMike Gerdts Op = Op->Asl.Next;
934*35786f68SRobert Mustacchi OpPreviouslyVisited = FALSE;
935bc36eafdSMike Gerdts }
936bc36eafdSMike Gerdts else
937bc36eafdSMike Gerdts {
938bc36eafdSMike Gerdts /* No children or peers, re-visit parent */
939bc36eafdSMike Gerdts
940bc36eafdSMike Gerdts if (Level != 0 )
941bc36eafdSMike Gerdts {
942bc36eafdSMike Gerdts Level--;
943bc36eafdSMike Gerdts }
944bc36eafdSMike Gerdts Op = Op->Asl.Parent;
945*35786f68SRobert Mustacchi OpPreviouslyVisited = TRUE;
946bc36eafdSMike Gerdts }
947bc36eafdSMike Gerdts }
948bc36eafdSMike Gerdts break;
949bc36eafdSMike Gerdts
950bc36eafdSMike Gerdts case ASL_WALK_VISIT_TWICE:
951bc36eafdSMike Gerdts
952bc36eafdSMike Gerdts while (Op)
953bc36eafdSMike Gerdts {
954*35786f68SRobert Mustacchi if (OpPreviouslyVisited)
955bc36eafdSMike Gerdts {
956bc36eafdSMike Gerdts Status = AscendingCallback (Op, Level, Context);
957bc36eafdSMike Gerdts if (ACPI_FAILURE (Status))
958bc36eafdSMike Gerdts {
959bc36eafdSMike Gerdts return (Status);
960bc36eafdSMike Gerdts }
961bc36eafdSMike Gerdts }
962bc36eafdSMike Gerdts else
963bc36eafdSMike Gerdts {
964*35786f68SRobert Mustacchi /* Let the callback process the op. */
965bc36eafdSMike Gerdts
966bc36eafdSMike Gerdts Status = DescendingCallback (Op, Level, Context);
967bc36eafdSMike Gerdts if (ACPI_SUCCESS (Status))
968bc36eafdSMike Gerdts {
969bc36eafdSMike Gerdts /* Visit children first, once */
970bc36eafdSMike Gerdts
971bc36eafdSMike Gerdts if (Op->Asl.Child)
972bc36eafdSMike Gerdts {
973bc36eafdSMike Gerdts Level++;
974bc36eafdSMike Gerdts Op = Op->Asl.Child;
975bc36eafdSMike Gerdts continue;
976bc36eafdSMike Gerdts }
977bc36eafdSMike Gerdts }
978bc36eafdSMike Gerdts else if (Status != AE_CTRL_DEPTH)
979bc36eafdSMike Gerdts {
980bc36eafdSMike Gerdts /* Exit immediately on any error */
981bc36eafdSMike Gerdts
982bc36eafdSMike Gerdts return (Status);
983bc36eafdSMike Gerdts }
984bc36eafdSMike Gerdts }
985bc36eafdSMike Gerdts
986bc36eafdSMike Gerdts /* Terminate walk at start op */
987bc36eafdSMike Gerdts
988bc36eafdSMike Gerdts if (Op == StartOp)
989bc36eafdSMike Gerdts {
990bc36eafdSMike Gerdts break;
991bc36eafdSMike Gerdts }
992bc36eafdSMike Gerdts
993bc36eafdSMike Gerdts /* No more children, visit peers */
994bc36eafdSMike Gerdts
995bc36eafdSMike Gerdts if (Op->Asl.Next)
996bc36eafdSMike Gerdts {
997bc36eafdSMike Gerdts Op = Op->Asl.Next;
998*35786f68SRobert Mustacchi OpPreviouslyVisited = FALSE;
999bc36eafdSMike Gerdts }
1000bc36eafdSMike Gerdts else
1001bc36eafdSMike Gerdts {
1002bc36eafdSMike Gerdts /* No children or peers, re-visit parent */
1003bc36eafdSMike Gerdts
1004bc36eafdSMike Gerdts if (Level != 0 )
1005bc36eafdSMike Gerdts {
1006bc36eafdSMike Gerdts Level--;
1007bc36eafdSMike Gerdts }
1008bc36eafdSMike Gerdts Op = Op->Asl.Parent;
1009*35786f68SRobert Mustacchi OpPreviouslyVisited = TRUE;
1010bc36eafdSMike Gerdts }
1011bc36eafdSMike Gerdts }
1012bc36eafdSMike Gerdts break;
1013bc36eafdSMike Gerdts
1014bc36eafdSMike Gerdts default:
1015bc36eafdSMike Gerdts /* No other types supported */
1016bc36eafdSMike Gerdts break;
1017bc36eafdSMike Gerdts }
1018bc36eafdSMike Gerdts
1019bc36eafdSMike Gerdts /* If we get here, the walk completed with no errors */
1020bc36eafdSMike Gerdts
1021bc36eafdSMike Gerdts return (AE_OK);
1022bc36eafdSMike Gerdts }
1023