ReactOS 0.4.16-dev-257-g6aa11ac
psscope.c
Go to the documentation of this file.
1/******************************************************************************
2 *
3 * Module Name: psscope - Parser scope stack management routines
4 *
5 *****************************************************************************/
6
7/*
8 * Copyright (C) 2000 - 2022, Intel Corp.
9 * All rights reserved.
10 *
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
13 * are met:
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.
25 *
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.
29 *
30 * NO WARRANTY
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 MERCHANTABILITY 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.
42 */
43
44#include "acpi.h"
45#include "accommon.h"
46#include "acparser.h"
47
48#define _COMPONENT ACPI_PARSER
49 ACPI_MODULE_NAME ("psscope")
50
51
52/*******************************************************************************
53 *
54 * FUNCTION: AcpiPsGetParentScope
55 *
56 * PARAMETERS: ParserState - Current parser state object
57 *
58 * RETURN: Pointer to an Op object
59 *
60 * DESCRIPTION: Get parent of current op being parsed
61 *
62 ******************************************************************************/
63
66 ACPI_PARSE_STATE *ParserState)
67{
68
69 return (ParserState->Scope->ParseScope.Op);
70}
71
72
73/*******************************************************************************
74 *
75 * FUNCTION: AcpiPsHasCompletedScope
76 *
77 * PARAMETERS: ParserState - Current parser state object
78 *
79 * RETURN: Boolean, TRUE = scope completed.
80 *
81 * DESCRIPTION: Is parsing of current argument complete? Determined by
82 * 1) AML pointer is at or beyond the end of the scope
83 * 2) The scope argument count has reached zero.
84 *
85 ******************************************************************************/
86
89 ACPI_PARSE_STATE *ParserState)
90{
91
92 return ((BOOLEAN)
93 ((ParserState->Aml >= ParserState->Scope->ParseScope.ArgEnd ||
94 !ParserState->Scope->ParseScope.ArgCount)));
95}
96
97
98/*******************************************************************************
99 *
100 * FUNCTION: AcpiPsInitScope
101 *
102 * PARAMETERS: ParserState - Current parser state object
103 * Root - the Root Node of this new scope
104 *
105 * RETURN: Status
106 *
107 * DESCRIPTION: Allocate and init a new scope object
108 *
109 ******************************************************************************/
110
113 ACPI_PARSE_STATE *ParserState,
114 ACPI_PARSE_OBJECT *RootOp)
115{
116 ACPI_GENERIC_STATE *Scope;
117
118
119 ACPI_FUNCTION_TRACE_PTR (PsInitScope, RootOp);
120
121
122 Scope = AcpiUtCreateGenericState ();
123 if (!Scope)
124 {
126 }
127
128 Scope->Common.DescriptorType = ACPI_DESC_TYPE_STATE_RPSCOPE;
129 Scope->ParseScope.Op = RootOp;
131 Scope->ParseScope.ArgEnd = ParserState->AmlEnd;
132 Scope->ParseScope.PkgEnd = ParserState->AmlEnd;
133
134 ParserState->Scope = Scope;
135 ParserState->StartOp = RootOp;
136
138}
139
140
141/*******************************************************************************
142 *
143 * FUNCTION: AcpiPsPushScope
144 *
145 * PARAMETERS: ParserState - Current parser state object
146 * Op - Current op to be pushed
147 * RemainingArgs - List of args remaining
148 * ArgCount - Fixed or variable number of args
149 *
150 * RETURN: Status
151 *
152 * DESCRIPTION: Push current op to begin parsing its argument
153 *
154 ******************************************************************************/
155
158 ACPI_PARSE_STATE *ParserState,
160 UINT32 RemainingArgs,
161 UINT32 ArgCount)
162{
163 ACPI_GENERIC_STATE *Scope;
164
165
166 ACPI_FUNCTION_TRACE_PTR (PsPushScope, Op);
167
168
169 Scope = AcpiUtCreateGenericState ();
170 if (!Scope)
171 {
173 }
174
175 Scope->Common.DescriptorType = ACPI_DESC_TYPE_STATE_PSCOPE;
176 Scope->ParseScope.Op = Op;
177 Scope->ParseScope.ArgList = RemainingArgs;
178 Scope->ParseScope.ArgCount = ArgCount;
179 Scope->ParseScope.PkgEnd = ParserState->PkgEnd;
180
181 /* Push onto scope stack */
182
183 AcpiUtPushGenericState (&ParserState->Scope, Scope);
184
185 if (ArgCount == ACPI_VAR_ARGS)
186 {
187 /* Multiple arguments */
188
189 Scope->ParseScope.ArgEnd = ParserState->PkgEnd;
190 }
191 else
192 {
193 /* Single argument */
194
195 Scope->ParseScope.ArgEnd = ACPI_TO_POINTER (ACPI_MAX_PTR);
196 }
197
199}
200
201
202/*******************************************************************************
203 *
204 * FUNCTION: AcpiPsPopScope
205 *
206 * PARAMETERS: ParserState - Current parser state object
207 * Op - Where the popped op is returned
208 * ArgList - Where the popped "next argument" is
209 * returned
210 * ArgCount - Count of objects in ArgList
211 *
212 * RETURN: Status
213 *
214 * DESCRIPTION: Return to parsing a previous op
215 *
216 ******************************************************************************/
217
218void
220 ACPI_PARSE_STATE *ParserState,
222 UINT32 *ArgList,
223 UINT32 *ArgCount)
224{
225 ACPI_GENERIC_STATE *Scope = ParserState->Scope;
226
227
228 ACPI_FUNCTION_TRACE (PsPopScope);
229
230
231 /* Only pop the scope if there is in fact a next scope */
232
233 if (Scope->Common.Next)
234 {
235 Scope = AcpiUtPopGenericState (&ParserState->Scope);
236
237 /* Return to parsing previous op */
238
239 *Op = Scope->ParseScope.Op;
240 *ArgList = Scope->ParseScope.ArgList;
241 *ArgCount = Scope->ParseScope.ArgCount;
242 ParserState->PkgEnd = Scope->ParseScope.PkgEnd;
243
244 /* All done with this scope state structure */
245
247 }
248 else
249 {
250 /* Empty parse stack, prepare to fetch next opcode */
251
252 *Op = NULL;
253 *ArgList = 0;
254 *ArgCount = 0;
255 }
256
258 "Popped Op %p Args %X\n", *Op, *ArgCount));
260}
261
262
263/*******************************************************************************
264 *
265 * FUNCTION: AcpiPsCleanupScope
266 *
267 * PARAMETERS: ParserState - Current parser state object
268 *
269 * RETURN: None
270 *
271 * DESCRIPTION: Destroy available list, remaining stack levels, and return
272 * root scope
273 *
274 ******************************************************************************/
275
276void
278 ACPI_PARSE_STATE *ParserState)
279{
280 ACPI_GENERIC_STATE *Scope;
281
282
283 ACPI_FUNCTION_TRACE_PTR (PsCleanupScope, ParserState);
284
285
286 if (!ParserState)
287 {
289 }
290
291 /* Delete anything on the scope stack */
292
293 while (ParserState->Scope)
294 {
295 Scope = AcpiUtPopGenericState (&ParserState->Scope);
297 }
298
300}
unsigned char BOOLEAN
unsigned int UINT32
#define AE_NO_MEMORY
Definition: acexcep.h:112
#define AE_OK
Definition: acexcep.h:97
#define ACPI_DESC_TYPE_STATE_PSCOPE
Definition: acobject.h:569
#define ACPI_DESC_TYPE_STATE_RPSCOPE
Definition: acobject.h:568
#define ACPI_DEBUG_PRINT(pl)
Definition: acoutput.h:475
#define ACPI_DB_PARSE
Definition: acoutput.h:162
#define ACPI_MODULE_NAME(Name)
Definition: acoutput.h:216
#define ACPI_FUNCTION_TRACE_PTR(a, b)
Definition: acoutput.h:481
#define return_ACPI_STATUS(s)
Definition: acoutput.h:496
#define ACPI_FUNCTION_TRACE(a)
Definition: acoutput.h:480
#define return_VOID
Definition: acoutput.h:495
#define ACPI_VAR_ARGS
Definition: acparser.h:52
UINT32 ACPI_STATUS
Definition: actypes.h:460
#define ACPI_TO_POINTER(i)
Definition: actypes.h:552
ACPI_GENERIC_STATE * AcpiUtCreateGenericState(void)
Definition: utstate.c:130
ACPI_GENERIC_STATE * AcpiUtPopGenericState(ACPI_GENERIC_STATE **ListHead)
Definition: utstate.c:93
void AcpiUtPushGenericState(ACPI_GENERIC_STATE **ListHead, ACPI_GENERIC_STATE *State)
Definition: utstate.c:65
void AcpiUtDeleteGenericState(ACPI_GENERIC_STATE *State)
Definition: utstate.c:340
#define NULL
Definition: types.h:112
ACPI_PARSE_OBJECT * AcpiPsGetParentScope(ACPI_PARSE_STATE *ParserState)
Definition: psscope.c:65
void AcpiPsCleanupScope(ACPI_PARSE_STATE *ParserState)
Definition: psscope.c:277
ACPI_STATUS AcpiPsInitScope(ACPI_PARSE_STATE *ParserState, ACPI_PARSE_OBJECT *RootOp)
Definition: psscope.c:112
ACPI_STATUS AcpiPsPushScope(ACPI_PARSE_STATE *ParserState, ACPI_PARSE_OBJECT *Op, UINT32 RemainingArgs, UINT32 ArgCount)
Definition: psscope.c:157
void AcpiPsPopScope(ACPI_PARSE_STATE *ParserState, ACPI_PARSE_OBJECT **Op, UINT32 *ArgList, UINT32 *ArgCount)
Definition: psscope.c:219
BOOLEAN AcpiPsHasCompletedScope(ACPI_PARSE_STATE *ParserState)
Definition: psscope.c:88
union acpi_parse_object * StartOp
Definition: aclocal.h:1106
union acpi_generic_state * Scope
Definition: aclocal.h:1108
UINT8 * PkgEnd
Definition: aclocal.h:1105
UINT8 * AmlEnd
Definition: aclocal.h:1103
UINT8 * PkgEnd
Definition: aclocal.h:751
UINT32 ArgList
Definition: aclocal.h:752
union acpi_parse_object * Op
Definition: aclocal.h:749
UINT8 * ArgEnd
Definition: aclocal.h:750
ACPI_STATE_COMMON UINT32 ArgCount
Definition: aclocal.h:748
ACPI_COMMON_STATE Common
Definition: aclocal.h:822
ACPI_PSCOPE_STATE ParseScope
Definition: aclocal.h:826