1 /******************************************************************************
3 * Module Name: psscope - Parser scope stack management routines
5 *****************************************************************************/
8 * Copyright (C) 2000 - 2005, R. Byron Moore
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.
45 #include <acpi/acpi.h>
46 #include <acpi/acparser.h>
48 #define _COMPONENT ACPI_PARSER
49 ACPI_MODULE_NAME ("psscope")
52 /*******************************************************************************
54 * FUNCTION: acpi_ps_get_parent_scope
56 * PARAMETERS: parser_state - Current parser state object
58 * RETURN: Pointer to an Op object
60 * DESCRIPTION: Get parent of current op being parsed
62 ******************************************************************************/
64 union acpi_parse_object
*
65 acpi_ps_get_parent_scope (
66 struct acpi_parse_state
*parser_state
)
68 return (parser_state
->scope
->parse_scope
.op
);
72 /*******************************************************************************
74 * FUNCTION: acpi_ps_has_completed_scope
76 * PARAMETERS: parser_state - Current parser state object
78 * RETURN: Boolean, TRUE = scope completed.
80 * DESCRIPTION: Is parsing of current argument complete? Determined by
81 * 1) AML pointer is at or beyond the end of the scope
82 * 2) The scope argument count has reached zero.
84 ******************************************************************************/
87 acpi_ps_has_completed_scope (
88 struct acpi_parse_state
*parser_state
)
90 return ((u8
) ((parser_state
->aml
>= parser_state
->scope
->parse_scope
.arg_end
||
91 !parser_state
->scope
->parse_scope
.arg_count
)));
95 /*******************************************************************************
97 * FUNCTION: acpi_ps_init_scope
99 * PARAMETERS: parser_state - Current parser state object
100 * Root - the Root Node of this new scope
104 * DESCRIPTION: Allocate and init a new scope object
106 ******************************************************************************/
110 struct acpi_parse_state
*parser_state
,
111 union acpi_parse_object
*root_op
)
113 union acpi_generic_state
*scope
;
116 ACPI_FUNCTION_TRACE_PTR ("ps_init_scope", root_op
);
119 scope
= acpi_ut_create_generic_state ();
121 return_ACPI_STATUS (AE_NO_MEMORY
);
124 scope
->common
.data_type
= ACPI_DESC_TYPE_STATE_RPSCOPE
;
125 scope
->parse_scope
.op
= root_op
;
126 scope
->parse_scope
.arg_count
= ACPI_VAR_ARGS
;
127 scope
->parse_scope
.arg_end
= parser_state
->aml_end
;
128 scope
->parse_scope
.pkg_end
= parser_state
->aml_end
;
130 parser_state
->scope
= scope
;
131 parser_state
->start_op
= root_op
;
133 return_ACPI_STATUS (AE_OK
);
137 /*******************************************************************************
139 * FUNCTION: acpi_ps_push_scope
141 * PARAMETERS: parser_state - Current parser state object
142 * Op - Current op to be pushed
143 * remaining_args - List of args remaining
144 * arg_count - Fixed or variable number of args
148 * DESCRIPTION: Push current op to begin parsing its argument
150 ******************************************************************************/
154 struct acpi_parse_state
*parser_state
,
155 union acpi_parse_object
*op
,
159 union acpi_generic_state
*scope
;
162 ACPI_FUNCTION_TRACE_PTR ("ps_push_scope", op
);
165 scope
= acpi_ut_create_generic_state ();
167 return_ACPI_STATUS (AE_NO_MEMORY
);
170 scope
->common
.data_type
= ACPI_DESC_TYPE_STATE_PSCOPE
;
171 scope
->parse_scope
.op
= op
;
172 scope
->parse_scope
.arg_list
= remaining_args
;
173 scope
->parse_scope
.arg_count
= arg_count
;
174 scope
->parse_scope
.pkg_end
= parser_state
->pkg_end
;
176 /* Push onto scope stack */
178 acpi_ut_push_generic_state (&parser_state
->scope
, scope
);
180 if (arg_count
== ACPI_VAR_ARGS
) {
181 /* multiple arguments */
183 scope
->parse_scope
.arg_end
= parser_state
->pkg_end
;
186 /* single argument */
188 scope
->parse_scope
.arg_end
= ACPI_TO_POINTER (ACPI_MAX_PTR
);
191 return_ACPI_STATUS (AE_OK
);
195 /*******************************************************************************
197 * FUNCTION: acpi_ps_pop_scope
199 * PARAMETERS: parser_state - Current parser state object
200 * Op - Where the popped op is returned
201 * arg_list - Where the popped "next argument" is
203 * arg_count - Count of objects in arg_list
207 * DESCRIPTION: Return to parsing a previous op
209 ******************************************************************************/
213 struct acpi_parse_state
*parser_state
,
214 union acpi_parse_object
**op
,
218 union acpi_generic_state
*scope
= parser_state
->scope
;
221 ACPI_FUNCTION_TRACE ("ps_pop_scope");
225 * Only pop the scope if there is in fact a next scope
227 if (scope
->common
.next
) {
228 scope
= acpi_ut_pop_generic_state (&parser_state
->scope
);
230 /* return to parsing previous op */
232 *op
= scope
->parse_scope
.op
;
233 *arg_list
= scope
->parse_scope
.arg_list
;
234 *arg_count
= scope
->parse_scope
.arg_count
;
235 parser_state
->pkg_end
= scope
->parse_scope
.pkg_end
;
237 /* All done with this scope state structure */
239 acpi_ut_delete_generic_state (scope
);
242 /* empty parse stack, prepare to fetch next opcode */
249 ACPI_DEBUG_PRINT ((ACPI_DB_PARSE
, "Popped Op %p Args %X\n", *op
, *arg_count
));
254 /*******************************************************************************
256 * FUNCTION: acpi_ps_cleanup_scope
258 * PARAMETERS: parser_state - Current parser state object
262 * DESCRIPTION: Destroy available list, remaining stack levels, and return
265 ******************************************************************************/
268 acpi_ps_cleanup_scope (
269 struct acpi_parse_state
*parser_state
)
271 union acpi_generic_state
*scope
;
274 ACPI_FUNCTION_TRACE_PTR ("ps_cleanup_scope", parser_state
);
281 /* Delete anything on the scope stack */
283 while (parser_state
->scope
) {
284 scope
= acpi_ut_pop_generic_state (&parser_state
->scope
);
285 acpi_ut_delete_generic_state (scope
);