1 /******************************************************************************
3 * Module Name: psscope - Parser scope stack management routines
5 *****************************************************************************/
8 * Copyright (C) 2000 - 2013, Intel Corp.
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
14 * 1. Redistributions of source code must retain the above copyright
15 * notice, this list of conditions, and the following disclaimer,
16 * without modification.
17 * 2. Redistributions in binary form must reproduce at minimum a disclaimer
18 * substantially similar to the "NO WARRANTY" disclaimer below
19 * ("Disclaimer") and any redistribution must be conditioned upon
20 * including a substantially similar Disclaimer requirement for further
21 * binary redistribution.
22 * 3. Neither the names of the above-listed copyright holders nor the names
23 * of any contributors may be used to endorse or promote products derived
24 * from this software without specific prior written permission.
26 * Alternatively, this software may be distributed under the terms of the
27 * GNU General Public License ("GPL") version 2 as published by the Free
28 * Software Foundation.
31 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
32 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
33 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
34 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
35 * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
36 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
37 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
38 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
39 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
40 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
41 * POSSIBILITY OF SUCH DAMAGES.
49 #define _COMPONENT ACPI_PARSER
50 ACPI_MODULE_NAME ("psscope")
53 /*******************************************************************************
55 * FUNCTION: AcpiPsGetParentScope
57 * PARAMETERS: ParserState - Current parser state object
59 * RETURN: Pointer to an Op object
61 * DESCRIPTION: Get parent of current op being parsed
63 ******************************************************************************/
66 AcpiPsGetParentScope (
67 ACPI_PARSE_STATE
*ParserState
)
70 return (ParserState
->Scope
->ParseScope
.Op
);
74 /*******************************************************************************
76 * FUNCTION: AcpiPsHasCompletedScope
78 * PARAMETERS: ParserState - Current parser state object
80 * RETURN: Boolean, TRUE = scope completed.
82 * DESCRIPTION: Is parsing of current argument complete? Determined by
83 * 1) AML pointer is at or beyond the end of the scope
84 * 2) The scope argument count has reached zero.
86 ******************************************************************************/
89 AcpiPsHasCompletedScope (
90 ACPI_PARSE_STATE
*ParserState
)
94 ((ParserState
->Aml
>= ParserState
->Scope
->ParseScope
.ArgEnd
||
95 !ParserState
->Scope
->ParseScope
.ArgCount
)));
99 /*******************************************************************************
101 * FUNCTION: AcpiPsInitScope
103 * PARAMETERS: ParserState - Current parser state object
104 * Root - the Root Node of this new scope
108 * DESCRIPTION: Allocate and init a new scope object
110 ******************************************************************************/
114 ACPI_PARSE_STATE
*ParserState
,
115 ACPI_PARSE_OBJECT
*RootOp
)
117 ACPI_GENERIC_STATE
*Scope
;
120 ACPI_FUNCTION_TRACE_PTR (PsInitScope
, RootOp
);
123 Scope
= AcpiUtCreateGenericState ();
126 return_ACPI_STATUS (AE_NO_MEMORY
);
129 Scope
->Common
.DescriptorType
= ACPI_DESC_TYPE_STATE_RPSCOPE
;
130 Scope
->ParseScope
.Op
= RootOp
;
131 Scope
->ParseScope
.ArgCount
= ACPI_VAR_ARGS
;
132 Scope
->ParseScope
.ArgEnd
= ParserState
->AmlEnd
;
133 Scope
->ParseScope
.PkgEnd
= ParserState
->AmlEnd
;
135 ParserState
->Scope
= Scope
;
136 ParserState
->StartOp
= RootOp
;
138 return_ACPI_STATUS (AE_OK
);
142 /*******************************************************************************
144 * FUNCTION: AcpiPsPushScope
146 * PARAMETERS: ParserState - Current parser state object
147 * Op - Current op to be pushed
148 * RemainingArgs - List of args remaining
149 * ArgCount - Fixed or variable number of args
153 * DESCRIPTION: Push current op to begin parsing its argument
155 ******************************************************************************/
159 ACPI_PARSE_STATE
*ParserState
,
160 ACPI_PARSE_OBJECT
*Op
,
161 UINT32 RemainingArgs
,
164 ACPI_GENERIC_STATE
*Scope
;
167 ACPI_FUNCTION_TRACE_PTR (PsPushScope
, Op
);
170 Scope
= AcpiUtCreateGenericState ();
173 return_ACPI_STATUS (AE_NO_MEMORY
);
176 Scope
->Common
.DescriptorType
= ACPI_DESC_TYPE_STATE_PSCOPE
;
177 Scope
->ParseScope
.Op
= Op
;
178 Scope
->ParseScope
.ArgList
= RemainingArgs
;
179 Scope
->ParseScope
.ArgCount
= ArgCount
;
180 Scope
->ParseScope
.PkgEnd
= ParserState
->PkgEnd
;
182 /* Push onto scope stack */
184 AcpiUtPushGenericState (&ParserState
->Scope
, Scope
);
186 if (ArgCount
== ACPI_VAR_ARGS
)
188 /* Multiple arguments */
190 Scope
->ParseScope
.ArgEnd
= ParserState
->PkgEnd
;
194 /* Single argument */
196 Scope
->ParseScope
.ArgEnd
= ACPI_TO_POINTER (ACPI_MAX_PTR
);
199 return_ACPI_STATUS (AE_OK
);
203 /*******************************************************************************
205 * FUNCTION: AcpiPsPopScope
207 * PARAMETERS: ParserState - Current parser state object
208 * Op - Where the popped op is returned
209 * ArgList - Where the popped "next argument" is
211 * ArgCount - Count of objects in ArgList
215 * DESCRIPTION: Return to parsing a previous op
217 ******************************************************************************/
221 ACPI_PARSE_STATE
*ParserState
,
222 ACPI_PARSE_OBJECT
**Op
,
226 ACPI_GENERIC_STATE
*Scope
= ParserState
->Scope
;
229 ACPI_FUNCTION_TRACE (PsPopScope
);
232 /* Only pop the scope if there is in fact a next scope */
234 if (Scope
->Common
.Next
)
236 Scope
= AcpiUtPopGenericState (&ParserState
->Scope
);
238 /* Return to parsing previous op */
240 *Op
= Scope
->ParseScope
.Op
;
241 *ArgList
= Scope
->ParseScope
.ArgList
;
242 *ArgCount
= Scope
->ParseScope
.ArgCount
;
243 ParserState
->PkgEnd
= Scope
->ParseScope
.PkgEnd
;
245 /* All done with this scope state structure */
247 AcpiUtDeleteGenericState (Scope
);
251 /* Empty parse stack, prepare to fetch next opcode */
258 ACPI_DEBUG_PRINT ((ACPI_DB_PARSE
,
259 "Popped Op %p Args %X\n", *Op
, *ArgCount
));
264 /*******************************************************************************
266 * FUNCTION: AcpiPsCleanupScope
268 * PARAMETERS: ParserState - Current parser state object
272 * DESCRIPTION: Destroy available list, remaining stack levels, and return
275 ******************************************************************************/
279 ACPI_PARSE_STATE
*ParserState
)
281 ACPI_GENERIC_STATE
*Scope
;
284 ACPI_FUNCTION_TRACE_PTR (PsCleanupScope
, ParserState
);
292 /* Delete anything on the scope stack */
294 while (ParserState
->Scope
)
296 Scope
= AcpiUtPopGenericState (&ParserState
->Scope
);
297 AcpiUtDeleteGenericState (Scope
);