psscope.c revision 1.1.1.2.2.2 1 1.1.1.2.2.2 bouyer /******************************************************************************
2 1.1.1.2.2.2 bouyer *
3 1.1.1.2.2.2 bouyer * Module Name: psscope - Parser scope stack management routines
4 1.1.1.2.2.2 bouyer *
5 1.1.1.2.2.2 bouyer *****************************************************************************/
6 1.1.1.2.2.2 bouyer
7 1.1.1.2.2.2 bouyer /*
8 1.1.1.2.2.2 bouyer * Copyright (C) 2000 - 2011, Intel Corp.
9 1.1.1.2.2.2 bouyer * All rights reserved.
10 1.1.1.2.2.2 bouyer *
11 1.1.1.2.2.2 bouyer * Redistribution and use in source and binary forms, with or without
12 1.1.1.2.2.2 bouyer * modification, are permitted provided that the following conditions
13 1.1.1.2.2.2 bouyer * are met:
14 1.1.1.2.2.2 bouyer * 1. Redistributions of source code must retain the above copyright
15 1.1.1.2.2.2 bouyer * notice, this list of conditions, and the following disclaimer,
16 1.1.1.2.2.2 bouyer * without modification.
17 1.1.1.2.2.2 bouyer * 2. Redistributions in binary form must reproduce at minimum a disclaimer
18 1.1.1.2.2.2 bouyer * substantially similar to the "NO WARRANTY" disclaimer below
19 1.1.1.2.2.2 bouyer * ("Disclaimer") and any redistribution must be conditioned upon
20 1.1.1.2.2.2 bouyer * including a substantially similar Disclaimer requirement for further
21 1.1.1.2.2.2 bouyer * binary redistribution.
22 1.1.1.2.2.2 bouyer * 3. Neither the names of the above-listed copyright holders nor the names
23 1.1.1.2.2.2 bouyer * of any contributors may be used to endorse or promote products derived
24 1.1.1.2.2.2 bouyer * from this software without specific prior written permission.
25 1.1.1.2.2.2 bouyer *
26 1.1.1.2.2.2 bouyer * Alternatively, this software may be distributed under the terms of the
27 1.1.1.2.2.2 bouyer * GNU General Public License ("GPL") version 2 as published by the Free
28 1.1.1.2.2.2 bouyer * Software Foundation.
29 1.1.1.2.2.2 bouyer *
30 1.1.1.2.2.2 bouyer * NO WARRANTY
31 1.1.1.2.2.2 bouyer * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
32 1.1.1.2.2.2 bouyer * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
33 1.1.1.2.2.2 bouyer * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
34 1.1.1.2.2.2 bouyer * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
35 1.1.1.2.2.2 bouyer * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
36 1.1.1.2.2.2 bouyer * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
37 1.1.1.2.2.2 bouyer * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
38 1.1.1.2.2.2 bouyer * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
39 1.1.1.2.2.2 bouyer * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
40 1.1.1.2.2.2 bouyer * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
41 1.1.1.2.2.2 bouyer * POSSIBILITY OF SUCH DAMAGES.
42 1.1.1.2.2.2 bouyer */
43 1.1.1.2.2.2 bouyer
44 1.1.1.2.2.2 bouyer
45 1.1.1.2.2.2 bouyer #include "acpi.h"
46 1.1.1.2.2.2 bouyer #include "accommon.h"
47 1.1.1.2.2.2 bouyer #include "acparser.h"
48 1.1.1.2.2.2 bouyer
49 1.1.1.2.2.2 bouyer #define _COMPONENT ACPI_PARSER
50 1.1.1.2.2.2 bouyer ACPI_MODULE_NAME ("psscope")
51 1.1.1.2.2.2 bouyer
52 1.1.1.2.2.2 bouyer
53 1.1.1.2.2.2 bouyer /*******************************************************************************
54 1.1.1.2.2.2 bouyer *
55 1.1.1.2.2.2 bouyer * FUNCTION: AcpiPsGetParentScope
56 1.1.1.2.2.2 bouyer *
57 1.1.1.2.2.2 bouyer * PARAMETERS: ParserState - Current parser state object
58 1.1.1.2.2.2 bouyer *
59 1.1.1.2.2.2 bouyer * RETURN: Pointer to an Op object
60 1.1.1.2.2.2 bouyer *
61 1.1.1.2.2.2 bouyer * DESCRIPTION: Get parent of current op being parsed
62 1.1.1.2.2.2 bouyer *
63 1.1.1.2.2.2 bouyer ******************************************************************************/
64 1.1.1.2.2.2 bouyer
65 1.1.1.2.2.2 bouyer ACPI_PARSE_OBJECT *
66 1.1.1.2.2.2 bouyer AcpiPsGetParentScope (
67 1.1.1.2.2.2 bouyer ACPI_PARSE_STATE *ParserState)
68 1.1.1.2.2.2 bouyer {
69 1.1.1.2.2.2 bouyer
70 1.1.1.2.2.2 bouyer return (ParserState->Scope->ParseScope.Op);
71 1.1.1.2.2.2 bouyer }
72 1.1.1.2.2.2 bouyer
73 1.1.1.2.2.2 bouyer
74 1.1.1.2.2.2 bouyer /*******************************************************************************
75 1.1.1.2.2.2 bouyer *
76 1.1.1.2.2.2 bouyer * FUNCTION: AcpiPsHasCompletedScope
77 1.1.1.2.2.2 bouyer *
78 1.1.1.2.2.2 bouyer * PARAMETERS: ParserState - Current parser state object
79 1.1.1.2.2.2 bouyer *
80 1.1.1.2.2.2 bouyer * RETURN: Boolean, TRUE = scope completed.
81 1.1.1.2.2.2 bouyer *
82 1.1.1.2.2.2 bouyer * DESCRIPTION: Is parsing of current argument complete? Determined by
83 1.1.1.2.2.2 bouyer * 1) AML pointer is at or beyond the end of the scope
84 1.1.1.2.2.2 bouyer * 2) The scope argument count has reached zero.
85 1.1.1.2.2.2 bouyer *
86 1.1.1.2.2.2 bouyer ******************************************************************************/
87 1.1.1.2.2.2 bouyer
88 1.1.1.2.2.2 bouyer BOOLEAN
89 1.1.1.2.2.2 bouyer AcpiPsHasCompletedScope (
90 1.1.1.2.2.2 bouyer ACPI_PARSE_STATE *ParserState)
91 1.1.1.2.2.2 bouyer {
92 1.1.1.2.2.2 bouyer
93 1.1.1.2.2.2 bouyer return ((BOOLEAN)
94 1.1.1.2.2.2 bouyer ((ParserState->Aml >= ParserState->Scope->ParseScope.ArgEnd ||
95 1.1.1.2.2.2 bouyer !ParserState->Scope->ParseScope.ArgCount)));
96 1.1.1.2.2.2 bouyer }
97 1.1.1.2.2.2 bouyer
98 1.1.1.2.2.2 bouyer
99 1.1.1.2.2.2 bouyer /*******************************************************************************
100 1.1.1.2.2.2 bouyer *
101 1.1.1.2.2.2 bouyer * FUNCTION: AcpiPsInitScope
102 1.1.1.2.2.2 bouyer *
103 1.1.1.2.2.2 bouyer * PARAMETERS: ParserState - Current parser state object
104 1.1.1.2.2.2 bouyer * Root - the Root Node of this new scope
105 1.1.1.2.2.2 bouyer *
106 1.1.1.2.2.2 bouyer * RETURN: Status
107 1.1.1.2.2.2 bouyer *
108 1.1.1.2.2.2 bouyer * DESCRIPTION: Allocate and init a new scope object
109 1.1.1.2.2.2 bouyer *
110 1.1.1.2.2.2 bouyer ******************************************************************************/
111 1.1.1.2.2.2 bouyer
112 1.1.1.2.2.2 bouyer ACPI_STATUS
113 1.1.1.2.2.2 bouyer AcpiPsInitScope (
114 1.1.1.2.2.2 bouyer ACPI_PARSE_STATE *ParserState,
115 1.1.1.2.2.2 bouyer ACPI_PARSE_OBJECT *RootOp)
116 1.1.1.2.2.2 bouyer {
117 1.1.1.2.2.2 bouyer ACPI_GENERIC_STATE *Scope;
118 1.1.1.2.2.2 bouyer
119 1.1.1.2.2.2 bouyer
120 1.1.1.2.2.2 bouyer ACPI_FUNCTION_TRACE_PTR (PsInitScope, RootOp);
121 1.1.1.2.2.2 bouyer
122 1.1.1.2.2.2 bouyer
123 1.1.1.2.2.2 bouyer Scope = AcpiUtCreateGenericState ();
124 1.1.1.2.2.2 bouyer if (!Scope)
125 1.1.1.2.2.2 bouyer {
126 1.1.1.2.2.2 bouyer return_ACPI_STATUS (AE_NO_MEMORY);
127 1.1.1.2.2.2 bouyer }
128 1.1.1.2.2.2 bouyer
129 1.1.1.2.2.2 bouyer Scope->Common.DescriptorType = ACPI_DESC_TYPE_STATE_RPSCOPE;
130 1.1.1.2.2.2 bouyer Scope->ParseScope.Op = RootOp;
131 1.1.1.2.2.2 bouyer Scope->ParseScope.ArgCount = ACPI_VAR_ARGS;
132 1.1.1.2.2.2 bouyer Scope->ParseScope.ArgEnd = ParserState->AmlEnd;
133 1.1.1.2.2.2 bouyer Scope->ParseScope.PkgEnd = ParserState->AmlEnd;
134 1.1.1.2.2.2 bouyer
135 1.1.1.2.2.2 bouyer ParserState->Scope = Scope;
136 1.1.1.2.2.2 bouyer ParserState->StartOp = RootOp;
137 1.1.1.2.2.2 bouyer
138 1.1.1.2.2.2 bouyer return_ACPI_STATUS (AE_OK);
139 1.1.1.2.2.2 bouyer }
140 1.1.1.2.2.2 bouyer
141 1.1.1.2.2.2 bouyer
142 1.1.1.2.2.2 bouyer /*******************************************************************************
143 1.1.1.2.2.2 bouyer *
144 1.1.1.2.2.2 bouyer * FUNCTION: AcpiPsPushScope
145 1.1.1.2.2.2 bouyer *
146 1.1.1.2.2.2 bouyer * PARAMETERS: ParserState - Current parser state object
147 1.1.1.2.2.2 bouyer * Op - Current op to be pushed
148 1.1.1.2.2.2 bouyer * RemainingArgs - List of args remaining
149 1.1.1.2.2.2 bouyer * ArgCount - Fixed or variable number of args
150 1.1.1.2.2.2 bouyer *
151 1.1.1.2.2.2 bouyer * RETURN: Status
152 1.1.1.2.2.2 bouyer *
153 1.1.1.2.2.2 bouyer * DESCRIPTION: Push current op to begin parsing its argument
154 1.1.1.2.2.2 bouyer *
155 1.1.1.2.2.2 bouyer ******************************************************************************/
156 1.1.1.2.2.2 bouyer
157 1.1.1.2.2.2 bouyer ACPI_STATUS
158 1.1.1.2.2.2 bouyer AcpiPsPushScope (
159 1.1.1.2.2.2 bouyer ACPI_PARSE_STATE *ParserState,
160 1.1.1.2.2.2 bouyer ACPI_PARSE_OBJECT *Op,
161 1.1.1.2.2.2 bouyer UINT32 RemainingArgs,
162 1.1.1.2.2.2 bouyer UINT32 ArgCount)
163 1.1.1.2.2.2 bouyer {
164 1.1.1.2.2.2 bouyer ACPI_GENERIC_STATE *Scope;
165 1.1.1.2.2.2 bouyer
166 1.1.1.2.2.2 bouyer
167 1.1.1.2.2.2 bouyer ACPI_FUNCTION_TRACE_PTR (PsPushScope, Op);
168 1.1.1.2.2.2 bouyer
169 1.1.1.2.2.2 bouyer
170 1.1.1.2.2.2 bouyer Scope = AcpiUtCreateGenericState ();
171 1.1.1.2.2.2 bouyer if (!Scope)
172 1.1.1.2.2.2 bouyer {
173 1.1.1.2.2.2 bouyer return_ACPI_STATUS (AE_NO_MEMORY);
174 1.1.1.2.2.2 bouyer }
175 1.1.1.2.2.2 bouyer
176 1.1.1.2.2.2 bouyer Scope->Common.DescriptorType = ACPI_DESC_TYPE_STATE_PSCOPE;
177 1.1.1.2.2.2 bouyer Scope->ParseScope.Op = Op;
178 1.1.1.2.2.2 bouyer Scope->ParseScope.ArgList = RemainingArgs;
179 1.1.1.2.2.2 bouyer Scope->ParseScope.ArgCount = ArgCount;
180 1.1.1.2.2.2 bouyer Scope->ParseScope.PkgEnd = ParserState->PkgEnd;
181 1.1.1.2.2.2 bouyer
182 1.1.1.2.2.2 bouyer /* Push onto scope stack */
183 1.1.1.2.2.2 bouyer
184 1.1.1.2.2.2 bouyer AcpiUtPushGenericState (&ParserState->Scope, Scope);
185 1.1.1.2.2.2 bouyer
186 1.1.1.2.2.2 bouyer if (ArgCount == ACPI_VAR_ARGS)
187 1.1.1.2.2.2 bouyer {
188 1.1.1.2.2.2 bouyer /* Multiple arguments */
189 1.1.1.2.2.2 bouyer
190 1.1.1.2.2.2 bouyer Scope->ParseScope.ArgEnd = ParserState->PkgEnd;
191 1.1.1.2.2.2 bouyer }
192 1.1.1.2.2.2 bouyer else
193 1.1.1.2.2.2 bouyer {
194 1.1.1.2.2.2 bouyer /* Single argument */
195 1.1.1.2.2.2 bouyer
196 1.1.1.2.2.2 bouyer Scope->ParseScope.ArgEnd = ACPI_TO_POINTER (ACPI_MAX_PTR);
197 1.1.1.2.2.2 bouyer }
198 1.1.1.2.2.2 bouyer
199 1.1.1.2.2.2 bouyer return_ACPI_STATUS (AE_OK);
200 1.1.1.2.2.2 bouyer }
201 1.1.1.2.2.2 bouyer
202 1.1.1.2.2.2 bouyer
203 1.1.1.2.2.2 bouyer /*******************************************************************************
204 1.1.1.2.2.2 bouyer *
205 1.1.1.2.2.2 bouyer * FUNCTION: AcpiPsPopScope
206 1.1.1.2.2.2 bouyer *
207 1.1.1.2.2.2 bouyer * PARAMETERS: ParserState - Current parser state object
208 1.1.1.2.2.2 bouyer * Op - Where the popped op is returned
209 1.1.1.2.2.2 bouyer * ArgList - Where the popped "next argument" is
210 1.1.1.2.2.2 bouyer * returned
211 1.1.1.2.2.2 bouyer * ArgCount - Count of objects in ArgList
212 1.1.1.2.2.2 bouyer *
213 1.1.1.2.2.2 bouyer * RETURN: Status
214 1.1.1.2.2.2 bouyer *
215 1.1.1.2.2.2 bouyer * DESCRIPTION: Return to parsing a previous op
216 1.1.1.2.2.2 bouyer *
217 1.1.1.2.2.2 bouyer ******************************************************************************/
218 1.1.1.2.2.2 bouyer
219 1.1.1.2.2.2 bouyer void
220 1.1.1.2.2.2 bouyer AcpiPsPopScope (
221 1.1.1.2.2.2 bouyer ACPI_PARSE_STATE *ParserState,
222 1.1.1.2.2.2 bouyer ACPI_PARSE_OBJECT **Op,
223 1.1.1.2.2.2 bouyer UINT32 *ArgList,
224 1.1.1.2.2.2 bouyer UINT32 *ArgCount)
225 1.1.1.2.2.2 bouyer {
226 1.1.1.2.2.2 bouyer ACPI_GENERIC_STATE *Scope = ParserState->Scope;
227 1.1.1.2.2.2 bouyer
228 1.1.1.2.2.2 bouyer
229 1.1.1.2.2.2 bouyer ACPI_FUNCTION_TRACE (PsPopScope);
230 1.1.1.2.2.2 bouyer
231 1.1.1.2.2.2 bouyer
232 1.1.1.2.2.2 bouyer /* Only pop the scope if there is in fact a next scope */
233 1.1.1.2.2.2 bouyer
234 1.1.1.2.2.2 bouyer if (Scope->Common.Next)
235 1.1.1.2.2.2 bouyer {
236 1.1.1.2.2.2 bouyer Scope = AcpiUtPopGenericState (&ParserState->Scope);
237 1.1.1.2.2.2 bouyer
238 1.1.1.2.2.2 bouyer /* Return to parsing previous op */
239 1.1.1.2.2.2 bouyer
240 1.1.1.2.2.2 bouyer *Op = Scope->ParseScope.Op;
241 1.1.1.2.2.2 bouyer *ArgList = Scope->ParseScope.ArgList;
242 1.1.1.2.2.2 bouyer *ArgCount = Scope->ParseScope.ArgCount;
243 1.1.1.2.2.2 bouyer ParserState->PkgEnd = Scope->ParseScope.PkgEnd;
244 1.1.1.2.2.2 bouyer
245 1.1.1.2.2.2 bouyer /* All done with this scope state structure */
246 1.1.1.2.2.2 bouyer
247 1.1.1.2.2.2 bouyer AcpiUtDeleteGenericState (Scope);
248 1.1.1.2.2.2 bouyer }
249 1.1.1.2.2.2 bouyer else
250 1.1.1.2.2.2 bouyer {
251 1.1.1.2.2.2 bouyer /* Empty parse stack, prepare to fetch next opcode */
252 1.1.1.2.2.2 bouyer
253 1.1.1.2.2.2 bouyer *Op = NULL;
254 1.1.1.2.2.2 bouyer *ArgList = 0;
255 1.1.1.2.2.2 bouyer *ArgCount = 0;
256 1.1.1.2.2.2 bouyer }
257 1.1.1.2.2.2 bouyer
258 1.1.1.2.2.2 bouyer ACPI_DEBUG_PRINT ((ACPI_DB_PARSE,
259 1.1.1.2.2.2 bouyer "Popped Op %p Args %X\n", *Op, *ArgCount));
260 1.1.1.2.2.2 bouyer return_VOID;
261 1.1.1.2.2.2 bouyer }
262 1.1.1.2.2.2 bouyer
263 1.1.1.2.2.2 bouyer
264 1.1.1.2.2.2 bouyer /*******************************************************************************
265 1.1.1.2.2.2 bouyer *
266 1.1.1.2.2.2 bouyer * FUNCTION: AcpiPsCleanupScope
267 1.1.1.2.2.2 bouyer *
268 1.1.1.2.2.2 bouyer * PARAMETERS: ParserState - Current parser state object
269 1.1.1.2.2.2 bouyer *
270 1.1.1.2.2.2 bouyer * RETURN: None
271 1.1.1.2.2.2 bouyer *
272 1.1.1.2.2.2 bouyer * DESCRIPTION: Destroy available list, remaining stack levels, and return
273 1.1.1.2.2.2 bouyer * root scope
274 1.1.1.2.2.2 bouyer *
275 1.1.1.2.2.2 bouyer ******************************************************************************/
276 1.1.1.2.2.2 bouyer
277 1.1.1.2.2.2 bouyer void
278 1.1.1.2.2.2 bouyer AcpiPsCleanupScope (
279 1.1.1.2.2.2 bouyer ACPI_PARSE_STATE *ParserState)
280 1.1.1.2.2.2 bouyer {
281 1.1.1.2.2.2 bouyer ACPI_GENERIC_STATE *Scope;
282 1.1.1.2.2.2 bouyer
283 1.1.1.2.2.2 bouyer
284 1.1.1.2.2.2 bouyer ACPI_FUNCTION_TRACE_PTR (PsCleanupScope, ParserState);
285 1.1.1.2.2.2 bouyer
286 1.1.1.2.2.2 bouyer
287 1.1.1.2.2.2 bouyer if (!ParserState)
288 1.1.1.2.2.2 bouyer {
289 1.1.1.2.2.2 bouyer return_VOID;
290 1.1.1.2.2.2 bouyer }
291 1.1.1.2.2.2 bouyer
292 1.1.1.2.2.2 bouyer /* Delete anything on the scope stack */
293 1.1.1.2.2.2 bouyer
294 1.1.1.2.2.2 bouyer while (ParserState->Scope)
295 1.1.1.2.2.2 bouyer {
296 1.1.1.2.2.2 bouyer Scope = AcpiUtPopGenericState (&ParserState->Scope);
297 1.1.1.2.2.2 bouyer AcpiUtDeleteGenericState (Scope);
298 1.1.1.2.2.2 bouyer }
299 1.1.1.2.2.2 bouyer
300 1.1.1.2.2.2 bouyer return_VOID;
301 1.1.1.2.2.2 bouyer }
302 1.1.1.2.2.2 bouyer
303