aslwalks.c revision 1.18 1 1.1 jruoho /******************************************************************************
2 1.1 jruoho *
3 1.2 christos * Module Name: aslwalks.c - Miscellaneous analytical parse tree walks
4 1.1 jruoho *
5 1.1 jruoho *****************************************************************************/
6 1.1 jruoho
7 1.18 christos /******************************************************************************
8 1.18 christos *
9 1.18 christos * 1. Copyright Notice
10 1.18 christos *
11 1.18 christos * Some or all of this work - Copyright (c) 1999 - 2024, Intel Corp.
12 1.1 jruoho * All rights reserved.
13 1.1 jruoho *
14 1.18 christos * 2. License
15 1.18 christos *
16 1.18 christos * 2.1. This is your license from Intel Corp. under its intellectual property
17 1.18 christos * rights. You may have additional license terms from the party that provided
18 1.18 christos * you this software, covering your right to use that party's intellectual
19 1.18 christos * property rights.
20 1.18 christos *
21 1.18 christos * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
22 1.18 christos * copy of the source code appearing in this file ("Covered Code") an
23 1.18 christos * irrevocable, perpetual, worldwide license under Intel's copyrights in the
24 1.18 christos * base code distributed originally by Intel ("Original Intel Code") to copy,
25 1.18 christos * make derivatives, distribute, use and display any portion of the Covered
26 1.18 christos * Code in any form, with the right to sublicense such rights; and
27 1.18 christos *
28 1.18 christos * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
29 1.18 christos * license (with the right to sublicense), under only those claims of Intel
30 1.18 christos * patents that are infringed by the Original Intel Code, to make, use, sell,
31 1.18 christos * offer to sell, and import the Covered Code and derivative works thereof
32 1.18 christos * solely to the minimum extent necessary to exercise the above copyright
33 1.18 christos * license, and in no event shall the patent license extend to any additions
34 1.18 christos * to or modifications of the Original Intel Code. No other license or right
35 1.18 christos * is granted directly or by implication, estoppel or otherwise;
36 1.18 christos *
37 1.18 christos * The above copyright and patent license is granted only if the following
38 1.18 christos * conditions are met:
39 1.18 christos *
40 1.18 christos * 3. Conditions
41 1.18 christos *
42 1.18 christos * 3.1. Redistribution of Source with Rights to Further Distribute Source.
43 1.18 christos * Redistribution of source code of any substantial portion of the Covered
44 1.18 christos * Code or modification with rights to further distribute source must include
45 1.18 christos * the above Copyright Notice, the above License, this list of Conditions,
46 1.18 christos * and the following Disclaimer and Export Compliance provision. In addition,
47 1.18 christos * Licensee must cause all Covered Code to which Licensee contributes to
48 1.18 christos * contain a file documenting the changes Licensee made to create that Covered
49 1.18 christos * Code and the date of any change. Licensee must include in that file the
50 1.18 christos * documentation of any changes made by any predecessor Licensee. Licensee
51 1.18 christos * must include a prominent statement that the modification is derived,
52 1.18 christos * directly or indirectly, from Original Intel Code.
53 1.18 christos *
54 1.18 christos * 3.2. Redistribution of Source with no Rights to Further Distribute Source.
55 1.18 christos * Redistribution of source code of any substantial portion of the Covered
56 1.18 christos * Code or modification without rights to further distribute source must
57 1.18 christos * include the following Disclaimer and Export Compliance provision in the
58 1.18 christos * documentation and/or other materials provided with distribution. In
59 1.18 christos * addition, Licensee may not authorize further sublicense of source of any
60 1.18 christos * portion of the Covered Code, and must include terms to the effect that the
61 1.18 christos * license from Licensee to its licensee is limited to the intellectual
62 1.18 christos * property embodied in the software Licensee provides to its licensee, and
63 1.18 christos * not to intellectual property embodied in modifications its licensee may
64 1.18 christos * make.
65 1.18 christos *
66 1.18 christos * 3.3. Redistribution of Executable. Redistribution in executable form of any
67 1.18 christos * substantial portion of the Covered Code or modification must reproduce the
68 1.18 christos * above Copyright Notice, and the following Disclaimer and Export Compliance
69 1.18 christos * provision in the documentation and/or other materials provided with the
70 1.18 christos * distribution.
71 1.18 christos *
72 1.18 christos * 3.4. Intel retains all right, title, and interest in and to the Original
73 1.18 christos * Intel Code.
74 1.18 christos *
75 1.18 christos * 3.5. Neither the name Intel nor any other trademark owned or controlled by
76 1.18 christos * Intel shall be used in advertising or otherwise to promote the sale, use or
77 1.18 christos * other dealings in products derived from or relating to the Covered Code
78 1.18 christos * without prior written authorization from Intel.
79 1.18 christos *
80 1.18 christos * 4. Disclaimer and Export Compliance
81 1.18 christos *
82 1.18 christos * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
83 1.18 christos * HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
84 1.18 christos * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE,
85 1.18 christos * INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY
86 1.18 christos * UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY
87 1.18 christos * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
88 1.18 christos * PARTICULAR PURPOSE.
89 1.18 christos *
90 1.18 christos * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
91 1.18 christos * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
92 1.18 christos * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
93 1.18 christos * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
94 1.18 christos * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
95 1.18 christos * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS
96 1.18 christos * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
97 1.18 christos * LIMITED REMEDY.
98 1.18 christos *
99 1.18 christos * 4.3. Licensee shall not export, either directly or indirectly, any of this
100 1.18 christos * software or system incorporating such software without first obtaining any
101 1.18 christos * required license or other approval from the U. S. Department of Commerce or
102 1.18 christos * any other agency or department of the United States Government. In the
103 1.18 christos * event Licensee exports any such software from the United States or
104 1.18 christos * re-exports any such software from a foreign destination, Licensee shall
105 1.18 christos * ensure that the distribution and export/re-export of the software is in
106 1.18 christos * compliance with all laws, regulations, orders, or other restrictions of the
107 1.18 christos * U.S. Export Administration Regulations. Licensee agrees that neither it nor
108 1.18 christos * any of its subsidiaries will export/re-export any technical data, process,
109 1.18 christos * software, or service, directly or indirectly, to any country for which the
110 1.18 christos * United States government or any agency thereof requires an export license,
111 1.18 christos * other governmental approval, or letter of assurance, without first obtaining
112 1.18 christos * such license, approval or letter.
113 1.18 christos *
114 1.18 christos *****************************************************************************
115 1.18 christos *
116 1.18 christos * Alternatively, you may choose to be licensed under the terms of the
117 1.18 christos * following license:
118 1.18 christos *
119 1.1 jruoho * Redistribution and use in source and binary forms, with or without
120 1.1 jruoho * modification, are permitted provided that the following conditions
121 1.1 jruoho * are met:
122 1.1 jruoho * 1. Redistributions of source code must retain the above copyright
123 1.1 jruoho * notice, this list of conditions, and the following disclaimer,
124 1.1 jruoho * without modification.
125 1.1 jruoho * 2. Redistributions in binary form must reproduce at minimum a disclaimer
126 1.1 jruoho * substantially similar to the "NO WARRANTY" disclaimer below
127 1.1 jruoho * ("Disclaimer") and any redistribution must be conditioned upon
128 1.1 jruoho * including a substantially similar Disclaimer requirement for further
129 1.1 jruoho * binary redistribution.
130 1.1 jruoho * 3. Neither the names of the above-listed copyright holders nor the names
131 1.1 jruoho * of any contributors may be used to endorse or promote products derived
132 1.1 jruoho * from this software without specific prior written permission.
133 1.1 jruoho *
134 1.1 jruoho * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
135 1.1 jruoho * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
136 1.15 christos * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
137 1.1 jruoho * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
138 1.18 christos * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
139 1.18 christos * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
140 1.18 christos * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
141 1.18 christos * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
142 1.18 christos * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
143 1.18 christos * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
144 1.18 christos * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
145 1.18 christos *
146 1.18 christos * Alternatively, you may choose to be licensed under the terms of the
147 1.18 christos * GNU General Public License ("GPL") version 2 as published by the Free
148 1.18 christos * Software Foundation.
149 1.18 christos *
150 1.18 christos *****************************************************************************/
151 1.1 jruoho
152 1.1 jruoho #include "aslcompiler.h"
153 1.1 jruoho #include "aslcompiler.y.h"
154 1.1 jruoho #include "acparser.h"
155 1.1 jruoho #include "amlcode.h"
156 1.1 jruoho
157 1.1 jruoho
158 1.1 jruoho #define _COMPONENT ACPI_COMPILER
159 1.1 jruoho ACPI_MODULE_NAME ("aslwalks")
160 1.1 jruoho
161 1.1 jruoho
162 1.5 christos /* Local prototypes */
163 1.5 christos
164 1.5 christos static void
165 1.5 christos AnAnalyzeStoreOperator (
166 1.5 christos ACPI_PARSE_OBJECT *Op);
167 1.5 christos
168 1.13 christos static BOOLEAN
169 1.13 christos AnIsValidBufferConstant (
170 1.13 christos ACPI_PARSE_OBJECT *Op);
171 1.13 christos
172 1.13 christos static void
173 1.13 christos AnValidateCreateBufferField (
174 1.13 christos ACPI_PARSE_OBJECT *CreateBufferFieldOp);
175 1.13 christos
176 1.5 christos
177 1.1 jruoho /*******************************************************************************
178 1.1 jruoho *
179 1.1 jruoho * FUNCTION: AnMethodTypingWalkEnd
180 1.1 jruoho *
181 1.1 jruoho * PARAMETERS: ASL_WALK_CALLBACK
182 1.1 jruoho *
183 1.1 jruoho * RETURN: Status
184 1.1 jruoho *
185 1.1 jruoho * DESCRIPTION: Ascending callback for typing walk. Complete the method
186 1.1 jruoho * return analysis. Check methods for:
187 1.1 jruoho * 1) Initialized local variables
188 1.1 jruoho * 2) Valid arguments
189 1.1 jruoho * 3) Return types
190 1.1 jruoho *
191 1.1 jruoho ******************************************************************************/
192 1.1 jruoho
193 1.1 jruoho ACPI_STATUS
194 1.1 jruoho AnMethodTypingWalkEnd (
195 1.1 jruoho ACPI_PARSE_OBJECT *Op,
196 1.1 jruoho UINT32 Level,
197 1.1 jruoho void *Context)
198 1.1 jruoho {
199 1.5 christos UINT32 ThisOpBtype;
200 1.1 jruoho
201 1.1 jruoho
202 1.1 jruoho switch (Op->Asl.ParseOpcode)
203 1.1 jruoho {
204 1.1 jruoho case PARSEOP_METHOD:
205 1.1 jruoho
206 1.9 christos Op->Asl.CompileFlags |= OP_METHOD_TYPED;
207 1.1 jruoho break;
208 1.1 jruoho
209 1.1 jruoho case PARSEOP_RETURN:
210 1.1 jruoho
211 1.1 jruoho if ((Op->Asl.Child) &&
212 1.1 jruoho (Op->Asl.Child->Asl.ParseOpcode != PARSEOP_DEFAULT_ARG))
213 1.1 jruoho {
214 1.5 christos ThisOpBtype = AnGetBtype (Op->Asl.Child);
215 1.1 jruoho
216 1.1 jruoho if ((Op->Asl.Child->Asl.ParseOpcode == PARSEOP_METHODCALL) &&
217 1.5 christos (ThisOpBtype == (ACPI_UINT32_MAX -1)))
218 1.1 jruoho {
219 1.1 jruoho /*
220 1.1 jruoho * The called method is untyped at this time (typically a
221 1.1 jruoho * forward reference).
222 1.1 jruoho *
223 1.6 christos * Check for a recursive method call first. Note: the
224 1.6 christos * Child->Node will be null if the method has not been
225 1.6 christos * resolved.
226 1.1 jruoho */
227 1.6 christos if (Op->Asl.Child->Asl.Node &&
228 1.6 christos (Op->Asl.ParentMethod != Op->Asl.Child->Asl.Node->Op))
229 1.1 jruoho {
230 1.1 jruoho /* We must type the method here */
231 1.1 jruoho
232 1.1 jruoho TrWalkParseTree (Op->Asl.Child->Asl.Node->Op,
233 1.1 jruoho ASL_WALK_VISIT_UPWARD, NULL,
234 1.1 jruoho AnMethodTypingWalkEnd, NULL);
235 1.1 jruoho
236 1.5 christos ThisOpBtype = AnGetBtype (Op->Asl.Child);
237 1.1 jruoho }
238 1.1 jruoho }
239 1.1 jruoho
240 1.1 jruoho /* Returns a value, save the value type */
241 1.1 jruoho
242 1.1 jruoho if (Op->Asl.ParentMethod)
243 1.1 jruoho {
244 1.5 christos Op->Asl.ParentMethod->Asl.AcpiBtype |= ThisOpBtype;
245 1.1 jruoho }
246 1.1 jruoho }
247 1.1 jruoho break;
248 1.1 jruoho
249 1.1 jruoho default:
250 1.2 christos
251 1.1 jruoho break;
252 1.1 jruoho }
253 1.1 jruoho
254 1.1 jruoho return (AE_OK);
255 1.1 jruoho }
256 1.1 jruoho
257 1.1 jruoho
258 1.1 jruoho /*******************************************************************************
259 1.1 jruoho *
260 1.1 jruoho * FUNCTION: AnOperandTypecheckWalkEnd
261 1.1 jruoho *
262 1.1 jruoho * PARAMETERS: ASL_WALK_CALLBACK
263 1.1 jruoho *
264 1.1 jruoho * RETURN: Status
265 1.1 jruoho *
266 1.1 jruoho * DESCRIPTION: Ascending callback for analysis walk. Complete method
267 1.1 jruoho * return analysis.
268 1.1 jruoho *
269 1.1 jruoho ******************************************************************************/
270 1.1 jruoho
271 1.1 jruoho ACPI_STATUS
272 1.1 jruoho AnOperandTypecheckWalkEnd (
273 1.1 jruoho ACPI_PARSE_OBJECT *Op,
274 1.1 jruoho UINT32 Level,
275 1.1 jruoho void *Context)
276 1.1 jruoho {
277 1.1 jruoho const ACPI_OPCODE_INFO *OpInfo;
278 1.1 jruoho UINT32 RuntimeArgTypes;
279 1.1 jruoho UINT32 RuntimeArgTypes2;
280 1.1 jruoho UINT32 RequiredBtypes;
281 1.1 jruoho UINT32 ThisNodeBtype;
282 1.1 jruoho UINT32 CommonBtypes;
283 1.1 jruoho UINT32 OpcodeClass;
284 1.1 jruoho ACPI_PARSE_OBJECT *ArgOp;
285 1.1 jruoho UINT32 ArgType;
286 1.1 jruoho
287 1.1 jruoho
288 1.1 jruoho switch (Op->Asl.AmlOpcode)
289 1.1 jruoho {
290 1.1 jruoho case AML_RAW_DATA_BYTE:
291 1.1 jruoho case AML_RAW_DATA_WORD:
292 1.1 jruoho case AML_RAW_DATA_DWORD:
293 1.1 jruoho case AML_RAW_DATA_QWORD:
294 1.1 jruoho case AML_RAW_DATA_BUFFER:
295 1.1 jruoho case AML_RAW_DATA_CHAIN:
296 1.1 jruoho case AML_PACKAGE_LENGTH:
297 1.1 jruoho case AML_UNASSIGNED_OPCODE:
298 1.1 jruoho case AML_DEFAULT_ARG_OP:
299 1.1 jruoho
300 1.1 jruoho /* Ignore the internal (compiler-only) AML opcodes */
301 1.1 jruoho
302 1.1 jruoho return (AE_OK);
303 1.1 jruoho
304 1.1 jruoho default:
305 1.2 christos
306 1.1 jruoho break;
307 1.1 jruoho }
308 1.1 jruoho
309 1.1 jruoho OpInfo = AcpiPsGetOpcodeInfo (Op->Asl.AmlOpcode);
310 1.1 jruoho if (!OpInfo)
311 1.1 jruoho {
312 1.1 jruoho return (AE_OK);
313 1.1 jruoho }
314 1.1 jruoho
315 1.5 christos ArgOp = Op->Asl.Child;
316 1.5 christos OpcodeClass = OpInfo->Class;
317 1.1 jruoho RuntimeArgTypes = OpInfo->RuntimeArgs;
318 1.1 jruoho
319 1.1 jruoho #ifdef ASL_ERROR_NAMED_OBJECT_IN_WHILE
320 1.1 jruoho /*
321 1.1 jruoho * Update 11/2008: In practice, we can't perform this check. A simple
322 1.1 jruoho * analysis is not sufficient. Also, it can cause errors when compiling
323 1.1 jruoho * disassembled code because of the way Switch operators are implemented
324 1.1 jruoho * (a While(One) loop with a named temp variable created within.)
325 1.1 jruoho */
326 1.1 jruoho
327 1.1 jruoho /*
328 1.1 jruoho * If we are creating a named object, check if we are within a while loop
329 1.1 jruoho * by checking if the parent is a WHILE op. This is a simple analysis, but
330 1.1 jruoho * probably sufficient for many cases.
331 1.1 jruoho *
332 1.1 jruoho * Allow Scope(), Buffer(), and Package().
333 1.1 jruoho */
334 1.1 jruoho if (((OpcodeClass == AML_CLASS_NAMED_OBJECT) && (Op->Asl.AmlOpcode != AML_SCOPE_OP)) ||
335 1.1 jruoho ((OpcodeClass == AML_CLASS_CREATE) && (OpInfo->Flags & AML_NSNODE)))
336 1.1 jruoho {
337 1.1 jruoho if (Op->Asl.Parent->Asl.AmlOpcode == AML_WHILE_OP)
338 1.1 jruoho {
339 1.1 jruoho AslError (ASL_ERROR, ASL_MSG_NAMED_OBJECT_IN_WHILE, Op, NULL);
340 1.1 jruoho }
341 1.1 jruoho }
342 1.1 jruoho #endif
343 1.1 jruoho
344 1.1 jruoho /*
345 1.1 jruoho * Special case for control opcodes IF/RETURN/WHILE since they
346 1.1 jruoho * have no runtime arg list (at this time)
347 1.1 jruoho */
348 1.1 jruoho switch (Op->Asl.AmlOpcode)
349 1.1 jruoho {
350 1.1 jruoho case AML_IF_OP:
351 1.1 jruoho case AML_WHILE_OP:
352 1.1 jruoho case AML_RETURN_OP:
353 1.1 jruoho
354 1.1 jruoho if (ArgOp->Asl.ParseOpcode == PARSEOP_METHODCALL)
355 1.1 jruoho {
356 1.1 jruoho /* Check for an internal method */
357 1.1 jruoho
358 1.1 jruoho if (AnIsInternalMethod (ArgOp))
359 1.1 jruoho {
360 1.1 jruoho return (AE_OK);
361 1.1 jruoho }
362 1.1 jruoho
363 1.1 jruoho /* The lone arg is a method call, check it */
364 1.1 jruoho
365 1.1 jruoho RequiredBtypes = AnMapArgTypeToBtype (ARGI_INTEGER);
366 1.1 jruoho if (Op->Asl.AmlOpcode == AML_RETURN_OP)
367 1.1 jruoho {
368 1.1 jruoho RequiredBtypes = 0xFFFFFFFF;
369 1.1 jruoho }
370 1.1 jruoho
371 1.1 jruoho ThisNodeBtype = AnGetBtype (ArgOp);
372 1.1 jruoho if (ThisNodeBtype == ACPI_UINT32_MAX)
373 1.1 jruoho {
374 1.1 jruoho return (AE_OK);
375 1.1 jruoho }
376 1.5 christos
377 1.1 jruoho AnCheckMethodReturnValue (Op, OpInfo, ArgOp,
378 1.1 jruoho RequiredBtypes, ThisNodeBtype);
379 1.1 jruoho }
380 1.1 jruoho return (AE_OK);
381 1.1 jruoho
382 1.4 christos case AML_EXTERNAL_OP:
383 1.4 christos /*
384 1.4 christos * Not really a "runtime" opcode since it used by disassembler only.
385 1.4 christos * The parser will find any issues with the operands.
386 1.4 christos */
387 1.4 christos return (AE_OK);
388 1.4 christos
389 1.1 jruoho default:
390 1.2 christos
391 1.1 jruoho break;
392 1.1 jruoho }
393 1.1 jruoho
394 1.1 jruoho /* Ignore the non-executable opcodes */
395 1.1 jruoho
396 1.1 jruoho if (RuntimeArgTypes == ARGI_INVALID_OPCODE)
397 1.1 jruoho {
398 1.1 jruoho return (AE_OK);
399 1.1 jruoho }
400 1.1 jruoho
401 1.5 christos /*
402 1.5 christos * Special handling for certain opcodes.
403 1.5 christos */
404 1.5 christos switch (Op->Asl.AmlOpcode)
405 1.5 christos {
406 1.5 christos /* BankField has one TermArg */
407 1.5 christos
408 1.5 christos case AML_BANK_FIELD_OP:
409 1.5 christos
410 1.5 christos OpcodeClass = AML_CLASS_EXECUTE;
411 1.5 christos ArgOp = ArgOp->Asl.Next;
412 1.5 christos ArgOp = ArgOp->Asl.Next;
413 1.5 christos break;
414 1.5 christos
415 1.5 christos /* Operation Region has 2 TermArgs */
416 1.5 christos
417 1.5 christos case AML_REGION_OP:
418 1.5 christos
419 1.5 christos OpcodeClass = AML_CLASS_EXECUTE;
420 1.5 christos ArgOp = ArgOp->Asl.Next;
421 1.5 christos ArgOp = ArgOp->Asl.Next;
422 1.5 christos break;
423 1.5 christos
424 1.5 christos /* DataTableRegion has 3 TermArgs */
425 1.5 christos
426 1.5 christos case AML_DATA_REGION_OP:
427 1.5 christos
428 1.5 christos OpcodeClass = AML_CLASS_EXECUTE;
429 1.5 christos ArgOp = ArgOp->Asl.Next;
430 1.5 christos break;
431 1.5 christos
432 1.5 christos /* Buffers/Packages have a length that is a TermArg */
433 1.5 christos
434 1.5 christos case AML_BUFFER_OP:
435 1.5 christos case AML_PACKAGE_OP:
436 1.8 christos case AML_VARIABLE_PACKAGE_OP:
437 1.5 christos
438 1.5 christos /* If length is a constant, we are done */
439 1.5 christos
440 1.5 christos if ((ArgOp->Asl.ParseOpcode == PARSEOP_INTEGER) ||
441 1.5 christos (ArgOp->Asl.ParseOpcode == PARSEOP_RAW_DATA))
442 1.5 christos {
443 1.5 christos return (AE_OK);
444 1.5 christos }
445 1.5 christos break;
446 1.5 christos
447 1.5 christos /* Store can write any object to the Debug object */
448 1.5 christos
449 1.5 christos case AML_STORE_OP:
450 1.5 christos /*
451 1.5 christos * If this is a Store() to the Debug object, we don't need
452 1.5 christos * to perform any further validation -- because a Store of
453 1.5 christos * any object to Debug is permitted and supported.
454 1.5 christos */
455 1.5 christos if (ArgOp->Asl.Next->Asl.AmlOpcode == AML_DEBUG_OP)
456 1.5 christos {
457 1.5 christos return (AE_OK);
458 1.5 christos }
459 1.5 christos break;
460 1.5 christos
461 1.5 christos default:
462 1.5 christos break;
463 1.5 christos }
464 1.5 christos
465 1.1 jruoho switch (OpcodeClass)
466 1.1 jruoho {
467 1.1 jruoho case AML_CLASS_EXECUTE:
468 1.1 jruoho case AML_CLASS_CREATE:
469 1.1 jruoho case AML_CLASS_CONTROL:
470 1.1 jruoho case AML_CLASS_RETURN_VALUE:
471 1.1 jruoho
472 1.1 jruoho /* Reverse the runtime argument list */
473 1.1 jruoho
474 1.1 jruoho RuntimeArgTypes2 = 0;
475 1.1 jruoho while ((ArgType = GET_CURRENT_ARG_TYPE (RuntimeArgTypes)))
476 1.1 jruoho {
477 1.1 jruoho RuntimeArgTypes2 <<= ARG_TYPE_WIDTH;
478 1.1 jruoho RuntimeArgTypes2 |= ArgType;
479 1.1 jruoho INCREMENT_ARG_LIST (RuntimeArgTypes);
480 1.1 jruoho }
481 1.1 jruoho
482 1.5 christos /* Typecheck each argument */
483 1.5 christos
484 1.1 jruoho while ((ArgType = GET_CURRENT_ARG_TYPE (RuntimeArgTypes2)))
485 1.1 jruoho {
486 1.5 christos /* Get the required type(s) for the argument */
487 1.5 christos
488 1.1 jruoho RequiredBtypes = AnMapArgTypeToBtype (ArgType);
489 1.1 jruoho
490 1.4 christos if (!ArgOp)
491 1.4 christos {
492 1.4 christos AslError (ASL_ERROR, ASL_MSG_COMPILER_INTERNAL, Op,
493 1.4 christos "Null ArgOp in argument loop");
494 1.4 christos AslAbort ();
495 1.4 christos }
496 1.4 christos
497 1.5 christos /* Get the actual type of the argument */
498 1.5 christos
499 1.1 jruoho ThisNodeBtype = AnGetBtype (ArgOp);
500 1.1 jruoho if (ThisNodeBtype == ACPI_UINT32_MAX)
501 1.1 jruoho {
502 1.1 jruoho goto NextArgument;
503 1.1 jruoho }
504 1.1 jruoho
505 1.1 jruoho /* Examine the arg based on the required type of the arg */
506 1.1 jruoho
507 1.1 jruoho switch (ArgType)
508 1.1 jruoho {
509 1.1 jruoho case ARGI_TARGETREF:
510 1.1 jruoho
511 1.1 jruoho if (ArgOp->Asl.ParseOpcode == PARSEOP_ZERO)
512 1.1 jruoho {
513 1.1 jruoho /* ZERO is the placeholder for "don't store result" */
514 1.1 jruoho
515 1.1 jruoho ThisNodeBtype = RequiredBtypes;
516 1.1 jruoho break;
517 1.1 jruoho }
518 1.1 jruoho
519 1.15 christos ACPI_FALLTHROUGH;
520 1.5 christos
521 1.5 christos case ARGI_STORE_TARGET:
522 1.5 christos
523 1.1 jruoho if (ArgOp->Asl.ParseOpcode == PARSEOP_INTEGER)
524 1.1 jruoho {
525 1.1 jruoho /*
526 1.1 jruoho * This is the case where an original reference to a resource
527 1.1 jruoho * descriptor field has been replaced by an (Integer) offset.
528 1.1 jruoho * These named fields are supported at compile-time only;
529 1.1 jruoho * the names are not passed to the interpreter (via the AML).
530 1.1 jruoho */
531 1.1 jruoho if ((ArgOp->Asl.Node->Type == ACPI_TYPE_LOCAL_RESOURCE_FIELD) ||
532 1.1 jruoho (ArgOp->Asl.Node->Type == ACPI_TYPE_LOCAL_RESOURCE))
533 1.1 jruoho {
534 1.5 christos AslError (ASL_ERROR, ASL_MSG_RESOURCE_FIELD,
535 1.5 christos ArgOp, NULL);
536 1.1 jruoho }
537 1.1 jruoho else
538 1.1 jruoho {
539 1.5 christos AslError (ASL_ERROR, ASL_MSG_INVALID_TYPE,
540 1.5 christos ArgOp, NULL);
541 1.1 jruoho }
542 1.1 jruoho }
543 1.1 jruoho break;
544 1.1 jruoho
545 1.1 jruoho
546 1.5 christos #ifdef __FUTURE_IMPLEMENTATION
547 1.5 christos /*
548 1.5 christos * Possible future typechecking support
549 1.5 christos */
550 1.1 jruoho case ARGI_REFERENCE: /* References */
551 1.1 jruoho case ARGI_INTEGER_REF:
552 1.1 jruoho case ARGI_OBJECT_REF:
553 1.1 jruoho case ARGI_DEVICE_REF:
554 1.1 jruoho
555 1.1 jruoho switch (ArgOp->Asl.ParseOpcode)
556 1.1 jruoho {
557 1.1 jruoho case PARSEOP_LOCAL0:
558 1.1 jruoho case PARSEOP_LOCAL1:
559 1.1 jruoho case PARSEOP_LOCAL2:
560 1.1 jruoho case PARSEOP_LOCAL3:
561 1.1 jruoho case PARSEOP_LOCAL4:
562 1.1 jruoho case PARSEOP_LOCAL5:
563 1.1 jruoho case PARSEOP_LOCAL6:
564 1.1 jruoho case PARSEOP_LOCAL7:
565 1.1 jruoho
566 1.1 jruoho /* TBD: implement analysis of current value (type) of the local */
567 1.1 jruoho /* For now, just treat any local as a typematch */
568 1.1 jruoho
569 1.1 jruoho /*ThisNodeBtype = RequiredBtypes;*/
570 1.1 jruoho break;
571 1.1 jruoho
572 1.1 jruoho case PARSEOP_ARG0:
573 1.1 jruoho case PARSEOP_ARG1:
574 1.1 jruoho case PARSEOP_ARG2:
575 1.1 jruoho case PARSEOP_ARG3:
576 1.1 jruoho case PARSEOP_ARG4:
577 1.1 jruoho case PARSEOP_ARG5:
578 1.1 jruoho case PARSEOP_ARG6:
579 1.1 jruoho
580 1.5 christos /* Hard to analyze argument types, so we won't */
581 1.5 christos /* for now. Just treat any arg as a typematch */
582 1.1 jruoho
583 1.1 jruoho /* ThisNodeBtype = RequiredBtypes; */
584 1.1 jruoho break;
585 1.1 jruoho
586 1.1 jruoho case PARSEOP_DEBUG:
587 1.1 jruoho case PARSEOP_REFOF:
588 1.1 jruoho case PARSEOP_INDEX:
589 1.1 jruoho default:
590 1.2 christos
591 1.1 jruoho break;
592 1.1 jruoho }
593 1.1 jruoho break;
594 1.5 christos #endif
595 1.1 jruoho case ARGI_INTEGER:
596 1.1 jruoho default:
597 1.2 christos
598 1.1 jruoho break;
599 1.1 jruoho }
600 1.1 jruoho
601 1.1 jruoho
602 1.5 christos /* Check for a type mismatch (required versus actual) */
603 1.5 christos
604 1.1 jruoho CommonBtypes = ThisNodeBtype & RequiredBtypes;
605 1.1 jruoho
606 1.1 jruoho if (ArgOp->Asl.ParseOpcode == PARSEOP_METHODCALL)
607 1.1 jruoho {
608 1.1 jruoho if (AnIsInternalMethod (ArgOp))
609 1.1 jruoho {
610 1.1 jruoho return (AE_OK);
611 1.1 jruoho }
612 1.1 jruoho
613 1.1 jruoho /* Check a method call for a valid return value */
614 1.1 jruoho
615 1.1 jruoho AnCheckMethodReturnValue (Op, OpInfo, ArgOp,
616 1.1 jruoho RequiredBtypes, ThisNodeBtype);
617 1.1 jruoho }
618 1.1 jruoho
619 1.1 jruoho /*
620 1.1 jruoho * Now check if the actual type(s) match at least one
621 1.1 jruoho * bit to the required type
622 1.1 jruoho */
623 1.1 jruoho else if (!CommonBtypes)
624 1.1 jruoho {
625 1.1 jruoho /* No match -- this is a type mismatch error */
626 1.1 jruoho
627 1.11 christos AnFormatBtype (AslGbl_StringBuffer, ThisNodeBtype);
628 1.11 christos AnFormatBtype (AslGbl_StringBuffer2, RequiredBtypes);
629 1.1 jruoho
630 1.11 christos snprintf (AslGbl_MsgBuffer, sizeof(AslGbl_MsgBuffer), "[%s] found, %s operator requires [%s]",
631 1.11 christos AslGbl_StringBuffer, OpInfo->Name, AslGbl_StringBuffer2);
632 1.1 jruoho
633 1.5 christos AslError (ASL_ERROR, ASL_MSG_INVALID_TYPE,
634 1.11 christos ArgOp, AslGbl_MsgBuffer);
635 1.1 jruoho }
636 1.1 jruoho
637 1.1 jruoho NextArgument:
638 1.1 jruoho ArgOp = ArgOp->Asl.Next;
639 1.1 jruoho INCREMENT_ARG_LIST (RuntimeArgTypes2);
640 1.1 jruoho }
641 1.1 jruoho break;
642 1.1 jruoho
643 1.1 jruoho default:
644 1.2 christos
645 1.1 jruoho break;
646 1.1 jruoho }
647 1.1 jruoho
648 1.1 jruoho return (AE_OK);
649 1.1 jruoho }
650 1.1 jruoho
651 1.1 jruoho
652 1.1 jruoho /*******************************************************************************
653 1.1 jruoho *
654 1.1 jruoho * FUNCTION: AnOtherSemanticAnalysisWalkBegin
655 1.1 jruoho *
656 1.1 jruoho * PARAMETERS: ASL_WALK_CALLBACK
657 1.1 jruoho *
658 1.1 jruoho * RETURN: Status
659 1.1 jruoho *
660 1.1 jruoho * DESCRIPTION: Descending callback for the analysis walk. Checks for
661 1.1 jruoho * miscellaneous issues in the code.
662 1.1 jruoho *
663 1.1 jruoho ******************************************************************************/
664 1.1 jruoho
665 1.1 jruoho ACPI_STATUS
666 1.1 jruoho AnOtherSemanticAnalysisWalkBegin (
667 1.1 jruoho ACPI_PARSE_OBJECT *Op,
668 1.1 jruoho UINT32 Level,
669 1.1 jruoho void *Context)
670 1.1 jruoho {
671 1.5 christos ACPI_PARSE_OBJECT *ArgOp;
672 1.5 christos ACPI_PARSE_OBJECT *PrevArgOp = NULL;
673 1.1 jruoho const ACPI_OPCODE_INFO *OpInfo;
674 1.2 christos ACPI_NAMESPACE_NODE *Node;
675 1.1 jruoho
676 1.1 jruoho
677 1.1 jruoho OpInfo = AcpiPsGetOpcodeInfo (Op->Asl.AmlOpcode);
678 1.1 jruoho
679 1.5 christos
680 1.13 christos if (OpInfo->Flags & AML_CREATE)
681 1.13 christos {
682 1.13 christos /* This group contains all of the Create Buffer Field operators */
683 1.13 christos
684 1.13 christos AnValidateCreateBufferField (Op);
685 1.13 christos return (AE_OK);
686 1.13 christos }
687 1.13 christos
688 1.1 jruoho /*
689 1.1 jruoho * Determine if an execution class operator actually does something by
690 1.1 jruoho * checking if it has a target and/or the function return value is used.
691 1.1 jruoho * (Target is optional, so a standalone statement can actually do nothing.)
692 1.1 jruoho */
693 1.1 jruoho if ((OpInfo->Class == AML_CLASS_EXECUTE) &&
694 1.1 jruoho (OpInfo->Flags & AML_HAS_RETVAL) &&
695 1.1 jruoho (!AnIsResultUsed (Op)))
696 1.1 jruoho {
697 1.1 jruoho if (OpInfo->Flags & AML_HAS_TARGET)
698 1.1 jruoho {
699 1.1 jruoho /*
700 1.5 christos * Find the target node, it is always the last child. If the target
701 1.1 jruoho * is not specified in the ASL, a default node of type Zero was
702 1.1 jruoho * created by the parser.
703 1.1 jruoho */
704 1.5 christos ArgOp = Op->Asl.Child;
705 1.5 christos while (ArgOp->Asl.Next)
706 1.1 jruoho {
707 1.5 christos PrevArgOp = ArgOp;
708 1.5 christos ArgOp = ArgOp->Asl.Next;
709 1.1 jruoho }
710 1.1 jruoho
711 1.1 jruoho /* Divide() is the only weird case, it has two targets */
712 1.1 jruoho
713 1.1 jruoho if (Op->Asl.AmlOpcode == AML_DIVIDE_OP)
714 1.1 jruoho {
715 1.5 christos if ((ArgOp->Asl.ParseOpcode == PARSEOP_ZERO) &&
716 1.5 christos (PrevArgOp) &&
717 1.5 christos (PrevArgOp->Asl.ParseOpcode == PARSEOP_ZERO))
718 1.1 jruoho {
719 1.2 christos AslError (ASL_ERROR, ASL_MSG_RESULT_NOT_USED,
720 1.1 jruoho Op, Op->Asl.ExternalName);
721 1.1 jruoho }
722 1.1 jruoho }
723 1.5 christos
724 1.5 christos else if (ArgOp->Asl.ParseOpcode == PARSEOP_ZERO)
725 1.1 jruoho {
726 1.2 christos AslError (ASL_ERROR, ASL_MSG_RESULT_NOT_USED,
727 1.1 jruoho Op, Op->Asl.ExternalName);
728 1.1 jruoho }
729 1.1 jruoho }
730 1.1 jruoho else
731 1.1 jruoho {
732 1.1 jruoho /*
733 1.1 jruoho * Has no target and the result is not used. Only a couple opcodes
734 1.1 jruoho * can have this combination.
735 1.1 jruoho */
736 1.1 jruoho switch (Op->Asl.ParseOpcode)
737 1.1 jruoho {
738 1.1 jruoho case PARSEOP_ACQUIRE:
739 1.1 jruoho case PARSEOP_WAIT:
740 1.1 jruoho case PARSEOP_LOADTABLE:
741 1.2 christos
742 1.1 jruoho break;
743 1.1 jruoho
744 1.1 jruoho default:
745 1.2 christos
746 1.2 christos AslError (ASL_ERROR, ASL_MSG_RESULT_NOT_USED,
747 1.1 jruoho Op, Op->Asl.ExternalName);
748 1.1 jruoho break;
749 1.1 jruoho }
750 1.1 jruoho }
751 1.1 jruoho }
752 1.1 jruoho
753 1.1 jruoho /*
754 1.1 jruoho * Semantic checks for individual ASL operators
755 1.1 jruoho */
756 1.13 christos
757 1.1 jruoho switch (Op->Asl.ParseOpcode)
758 1.1 jruoho {
759 1.5 christos case PARSEOP_STORE:
760 1.5 christos
761 1.11 christos if (AslGbl_DoTypechecking)
762 1.5 christos {
763 1.5 christos AnAnalyzeStoreOperator (Op);
764 1.5 christos }
765 1.5 christos break;
766 1.5 christos
767 1.5 christos
768 1.1 jruoho case PARSEOP_ACQUIRE:
769 1.1 jruoho case PARSEOP_WAIT:
770 1.1 jruoho /*
771 1.1 jruoho * Emit a warning if the timeout parameter for these operators is not
772 1.1 jruoho * ACPI_WAIT_FOREVER, and the result value from the operator is not
773 1.1 jruoho * checked, meaning that a timeout could happen, but the code
774 1.1 jruoho * would not know about it.
775 1.1 jruoho */
776 1.1 jruoho
777 1.1 jruoho /* First child is the namepath, 2nd child is timeout */
778 1.1 jruoho
779 1.5 christos ArgOp = Op->Asl.Child;
780 1.5 christos ArgOp = ArgOp->Asl.Next;
781 1.1 jruoho
782 1.1 jruoho /*
783 1.1 jruoho * Check for the WAIT_FOREVER case - defined by the ACPI spec to be
784 1.1 jruoho * 0xFFFF or greater
785 1.1 jruoho */
786 1.5 christos if (((ArgOp->Asl.ParseOpcode == PARSEOP_WORDCONST) ||
787 1.5 christos (ArgOp->Asl.ParseOpcode == PARSEOP_INTEGER)) &&
788 1.5 christos (ArgOp->Asl.Value.Integer >= (UINT64) ACPI_WAIT_FOREVER))
789 1.1 jruoho {
790 1.1 jruoho break;
791 1.1 jruoho }
792 1.1 jruoho
793 1.1 jruoho /*
794 1.1 jruoho * The operation could timeout. If the return value is not used
795 1.1 jruoho * (indicates timeout occurred), issue a warning
796 1.1 jruoho */
797 1.1 jruoho if (!AnIsResultUsed (Op))
798 1.1 jruoho {
799 1.5 christos AslError (ASL_WARNING, ASL_MSG_TIMEOUT, ArgOp,
800 1.1 jruoho Op->Asl.ExternalName);
801 1.1 jruoho }
802 1.1 jruoho break;
803 1.1 jruoho
804 1.2 christos case PARSEOP_CONNECTION:
805 1.2 christos /*
806 1.2 christos * Ensure that the referenced operation region has the correct SPACE_ID.
807 1.2 christos * From the grammar/parser, we know the parent is a FIELD definition.
808 1.2 christos */
809 1.5 christos ArgOp = Op->Asl.Parent; /* Field definition */
810 1.5 christos ArgOp = ArgOp->Asl.Child; /* First child is the OpRegion Name */
811 1.5 christos Node = ArgOp->Asl.Node; /* OpRegion namespace node */
812 1.3 christos if (!Node)
813 1.3 christos {
814 1.3 christos break;
815 1.3 christos }
816 1.2 christos
817 1.5 christos ArgOp = Node->Op; /* OpRegion definition */
818 1.5 christos ArgOp = ArgOp->Asl.Child; /* First child is the OpRegion Name */
819 1.5 christos ArgOp = ArgOp->Asl.Next; /* Next peer is the SPACE_ID (what we want) */
820 1.2 christos
821 1.2 christos /*
822 1.2 christos * The Connection() operator is only valid for the following operation
823 1.2 christos * region SpaceIds: GeneralPurposeIo and GenericSerialBus.
824 1.2 christos */
825 1.5 christos if ((ArgOp->Asl.Value.Integer != ACPI_ADR_SPACE_GPIO) &&
826 1.5 christos (ArgOp->Asl.Value.Integer != ACPI_ADR_SPACE_GSBUS))
827 1.2 christos {
828 1.2 christos AslError (ASL_ERROR, ASL_MSG_CONNECTION_INVALID, Op, NULL);
829 1.2 christos }
830 1.2 christos break;
831 1.2 christos
832 1.2 christos case PARSEOP_FIELD:
833 1.2 christos /*
834 1.2 christos * Ensure that fields for GeneralPurposeIo and GenericSerialBus
835 1.2 christos * contain at least one Connection() operator
836 1.2 christos */
837 1.5 christos ArgOp = Op->Asl.Child; /* 1st child is the OpRegion Name */
838 1.5 christos Node = ArgOp->Asl.Node; /* OpRegion namespace node */
839 1.2 christos if (!Node)
840 1.2 christos {
841 1.2 christos break;
842 1.2 christos }
843 1.2 christos
844 1.5 christos ArgOp = Node->Op; /* OpRegion definition */
845 1.5 christos ArgOp = ArgOp->Asl.Child; /* First child is the OpRegion Name */
846 1.5 christos ArgOp = ArgOp->Asl.Next; /* Next peer is the SPACE_ID (what we want) */
847 1.2 christos
848 1.2 christos /* We are only interested in GeneralPurposeIo and GenericSerialBus */
849 1.2 christos
850 1.5 christos if ((ArgOp->Asl.Value.Integer != ACPI_ADR_SPACE_GPIO) &&
851 1.5 christos (ArgOp->Asl.Value.Integer != ACPI_ADR_SPACE_GSBUS))
852 1.2 christos {
853 1.2 christos break;
854 1.2 christos }
855 1.2 christos
856 1.5 christos ArgOp = Op->Asl.Child; /* 1st child is the OpRegion Name */
857 1.5 christos ArgOp = ArgOp->Asl.Next; /* AccessType */
858 1.5 christos ArgOp = ArgOp->Asl.Next; /* LockRule */
859 1.5 christos ArgOp = ArgOp->Asl.Next; /* UpdateRule */
860 1.5 christos ArgOp = ArgOp->Asl.Next; /* Start of FieldUnitList */
861 1.2 christos
862 1.2 christos /* Walk the FieldUnitList */
863 1.2 christos
864 1.5 christos while (ArgOp)
865 1.2 christos {
866 1.5 christos if (ArgOp->Asl.ParseOpcode == PARSEOP_CONNECTION)
867 1.2 christos {
868 1.2 christos break;
869 1.2 christos }
870 1.5 christos else if (ArgOp->Asl.ParseOpcode == PARSEOP_NAMESEG)
871 1.2 christos {
872 1.5 christos AslError (ASL_ERROR, ASL_MSG_CONNECTION_MISSING, ArgOp, NULL);
873 1.2 christos break;
874 1.2 christos }
875 1.2 christos
876 1.5 christos ArgOp = ArgOp->Asl.Next;
877 1.2 christos }
878 1.2 christos break;
879 1.2 christos
880 1.1 jruoho default:
881 1.2 christos
882 1.1 jruoho break;
883 1.1 jruoho }
884 1.1 jruoho
885 1.1 jruoho return (AE_OK);
886 1.1 jruoho }
887 1.5 christos
888 1.5 christos
889 1.5 christos /*******************************************************************************
890 1.5 christos *
891 1.13 christos * FUNCTION: AnValidateCreateBufferField
892 1.13 christos *
893 1.13 christos * PARAMETERS: Op - A create buffer field operator
894 1.13 christos *
895 1.13 christos * RETURN: None
896 1.13 christos *
897 1.13 christos * DESCRIPTION: Check if a buffer index argument to a create buffer field
898 1.13 christos * operation is beyond the end of the target buffer.
899 1.13 christos *
900 1.13 christos * Validates these AML operators:
901 1.13 christos *
902 1.13 christos * AML_CREATE_FIELD_OP
903 1.13 christos * AML_CREATE_BIT_FIELD_OP
904 1.13 christos * AML_CREATE_BYTE_FIELD_OP
905 1.13 christos * AML_CREATE_WORD_FIELD_OP
906 1.13 christos * AML_CREATE_DWORD_FIELD_OP
907 1.13 christos * AML_CREATE_QWORD_FIELD_OP
908 1.13 christos *
909 1.13 christos * There are two conditions that must be satisfied in order to enable
910 1.13 christos * validation at compile time:
911 1.13 christos *
912 1.13 christos * 1) The length of the target buffer must be an integer constant
913 1.13 christos * 2) The index specified in the create* must be an integer constant
914 1.13 christos * 3) For CreateField, the bit length argument must be non-zero.
915 1.13 christos *
916 1.13 christos ******************************************************************************/
917 1.13 christos
918 1.13 christos static void
919 1.13 christos AnValidateCreateBufferField (
920 1.13 christos ACPI_PARSE_OBJECT *CreateBufferFieldOp)
921 1.13 christos {
922 1.13 christos ACPI_PARSE_OBJECT *TargetBufferOp;
923 1.13 christos ACPI_PARSE_OBJECT *ArgOp;
924 1.13 christos UINT32 TargetBufferLength;
925 1.13 christos UINT32 LastFieldByteIndex;
926 1.13 christos
927 1.13 christos
928 1.13 christos /*
929 1.13 christos * 1) Get the length of the target buffer
930 1.13 christos */
931 1.13 christos ArgOp = CreateBufferFieldOp->Asl.Child; /* Reference to target buffer */
932 1.13 christos
933 1.13 christos /*
934 1.13 christos * If no attached Node, the target buffer may be something like an
935 1.13 christos * ArgX or LocalX and cannot be evaluated at compile time.
936 1.13 christos */
937 1.13 christos if (!ArgOp->Asl.Node)
938 1.13 christos {
939 1.13 christos return;
940 1.13 christos }
941 1.13 christos
942 1.13 christos TargetBufferOp = ArgOp->Asl.Node->Op;
943 1.13 christos TargetBufferOp = TargetBufferOp->Asl.Child; /* Target buffer */
944 1.13 christos TargetBufferOp = TargetBufferOp->Asl.Next; /* "Buffer" keyword */
945 1.13 christos if (!TargetBufferOp)
946 1.13 christos {
947 1.13 christos /* Not a statement of the form NAME(XXXX, Buffer.... */
948 1.13 christos
949 1.13 christos return;
950 1.13 christos }
951 1.13 christos
952 1.13 christos /* Get the buffer length argument. It must be an integer constant */
953 1.13 christos
954 1.13 christos ArgOp = TargetBufferOp->Asl.Child;
955 1.13 christos if (!AnIsValidBufferConstant (ArgOp))
956 1.13 christos {
957 1.13 christos return;
958 1.13 christos }
959 1.13 christos
960 1.13 christos TargetBufferLength = (UINT32) ArgOp->Asl.Value.Integer;
961 1.13 christos
962 1.13 christos /*
963 1.13 christos * 2) Get the value of the buffer index argument. It must be
964 1.13 christos * an integer constant.
965 1.13 christos */
966 1.13 christos ArgOp = CreateBufferFieldOp->Asl.Child; /* Reference to target buffer */
967 1.13 christos ArgOp = ArgOp->Asl.Next; /* Buffer Index argument*/
968 1.13 christos if (!AnIsValidBufferConstant (ArgOp))
969 1.13 christos {
970 1.13 christos return;
971 1.13 christos }
972 1.13 christos
973 1.13 christos LastFieldByteIndex =
974 1.13 christos (UINT32) ArgOp->Asl.Value.Integer; /* Index can be in either bytes or bits */
975 1.13 christos
976 1.13 christos /*
977 1.13 christos * 3) Get the length of the new buffer field, in bytes. Also,
978 1.13 christos * create the final target buffer index for the last byte of the field
979 1.13 christos */
980 1.13 christos switch (CreateBufferFieldOp->Asl.ParseOpcode)
981 1.13 christos {
982 1.13 christos case PARSEOP_CREATEBITFIELD: /* A one bit field */
983 1.13 christos
984 1.13 christos LastFieldByteIndex = ACPI_ROUND_BITS_DOWN_TO_BYTES (LastFieldByteIndex);
985 1.13 christos break;
986 1.13 christos
987 1.13 christos case PARSEOP_CREATEBYTEFIELD:
988 1.13 christos break;
989 1.13 christos
990 1.13 christos case PARSEOP_CREATEWORDFIELD:
991 1.13 christos
992 1.13 christos LastFieldByteIndex += (sizeof (UINT16) - 1);
993 1.13 christos break;
994 1.13 christos
995 1.13 christos case PARSEOP_CREATEDWORDFIELD:
996 1.13 christos
997 1.13 christos LastFieldByteIndex += (sizeof (UINT32) - 1);
998 1.13 christos break;
999 1.13 christos
1000 1.13 christos case PARSEOP_CREATEQWORDFIELD:
1001 1.13 christos
1002 1.13 christos LastFieldByteIndex += (sizeof (UINT64) - 1);
1003 1.13 christos break;
1004 1.13 christos
1005 1.13 christos case PARSEOP_CREATEFIELD: /* Multi-bit field */
1006 1.13 christos
1007 1.13 christos ArgOp = ArgOp->Asl.Next; /* Length argument, in bits */
1008 1.13 christos if (!AnIsValidBufferConstant (ArgOp))
1009 1.13 christos {
1010 1.13 christos return;
1011 1.13 christos }
1012 1.13 christos
1013 1.13 christos /* The buffer field length is not allowed to be zero */
1014 1.13 christos
1015 1.13 christos if (ArgOp->Asl.Value.Integer == 0)
1016 1.13 christos {
1017 1.13 christos AslError (ASL_WARNING, ASL_MSG_BUFFER_FIELD_LENGTH, ArgOp, NULL);
1018 1.13 christos return;
1019 1.13 christos }
1020 1.13 christos
1021 1.13 christos LastFieldByteIndex +=
1022 1.13 christos ((UINT32) ArgOp->Asl.Value.Integer - 1); /* Create final bit index */
1023 1.13 christos
1024 1.13 christos /* Convert bit index to a byte index */
1025 1.13 christos
1026 1.13 christos LastFieldByteIndex = ACPI_ROUND_BITS_DOWN_TO_BYTES (LastFieldByteIndex);
1027 1.13 christos break;
1028 1.13 christos
1029 1.13 christos default:
1030 1.13 christos return;
1031 1.13 christos }
1032 1.13 christos
1033 1.13 christos /*
1034 1.13 christos * 4) Check for an access (index) beyond the end of the target buffer,
1035 1.13 christos * or a zero length target buffer.
1036 1.13 christos */
1037 1.13 christos if (!TargetBufferLength || (LastFieldByteIndex >= TargetBufferLength))
1038 1.13 christos {
1039 1.13 christos AslError (ASL_WARNING, ASL_MSG_BUFFER_FIELD_OVERFLOW, ArgOp, NULL);
1040 1.13 christos }
1041 1.13 christos }
1042 1.13 christos
1043 1.13 christos
1044 1.13 christos /*******************************************************************************
1045 1.13 christos *
1046 1.13 christos * FUNCTION: AnIsValidBufferConstant
1047 1.13 christos *
1048 1.13 christos * PARAMETERS: Op - A buffer-related operand
1049 1.13 christos *
1050 1.13 christos * RETURN: TRUE if operand is valid constant, FALSE otherwise
1051 1.13 christos *
1052 1.13 christos * DESCRIPTION: Check if the input Op is valid constant that can be used
1053 1.13 christos * in compile-time analysis.
1054 1.13 christos *
1055 1.13 christos ******************************************************************************/
1056 1.13 christos
1057 1.13 christos static BOOLEAN
1058 1.13 christos AnIsValidBufferConstant (
1059 1.13 christos ACPI_PARSE_OBJECT *Op)
1060 1.13 christos {
1061 1.13 christos if (!Op)
1062 1.13 christos {
1063 1.13 christos return (FALSE);
1064 1.13 christos }
1065 1.13 christos
1066 1.13 christos if ((Op->Asl.ParseOpcode == PARSEOP_INTEGER) ||
1067 1.13 christos (Op->Asl.ParseOpcode == PARSEOP_ZERO) ||
1068 1.13 christos (Op->Asl.ParseOpcode == PARSEOP_ONE))
1069 1.13 christos {
1070 1.13 christos return (TRUE);
1071 1.13 christos }
1072 1.13 christos
1073 1.13 christos return (FALSE);
1074 1.13 christos }
1075 1.13 christos
1076 1.13 christos
1077 1.13 christos /*******************************************************************************
1078 1.13 christos *
1079 1.5 christos * FUNCTION: AnAnalyzeStoreOperator
1080 1.5 christos *
1081 1.5 christos * PARAMETERS: Op - Store() operator
1082 1.5 christos *
1083 1.5 christos * RETURN: None
1084 1.5 christos *
1085 1.5 christos * DESCRIPTION: Analyze a store operator. Mostly for stores to/from package
1086 1.5 christos * objects where there are more restrictions than other data
1087 1.5 christos * types.
1088 1.5 christos *
1089 1.5 christos ******************************************************************************/
1090 1.5 christos
1091 1.5 christos static void
1092 1.5 christos AnAnalyzeStoreOperator (
1093 1.5 christos ACPI_PARSE_OBJECT *Op)
1094 1.5 christos {
1095 1.5 christos ACPI_NAMESPACE_NODE *SourceNode;
1096 1.5 christos ACPI_NAMESPACE_NODE *TargetNode;
1097 1.5 christos ACPI_PARSE_OBJECT *SourceOperandOp;
1098 1.5 christos ACPI_PARSE_OBJECT *TargetOperandOp;
1099 1.5 christos UINT32 SourceOperandBtype;
1100 1.5 christos UINT32 TargetOperandBtype;
1101 1.5 christos
1102 1.5 christos
1103 1.5 christos /* Extract the two operands for STORE */
1104 1.5 christos
1105 1.5 christos SourceOperandOp = Op->Asl.Child;
1106 1.5 christos TargetOperandOp = SourceOperandOp->Asl.Next;
1107 1.5 christos
1108 1.5 christos /*
1109 1.5 christos * Ignore these Source operand opcodes, they cannot be typechecked,
1110 1.5 christos * the actual result is unknown here.
1111 1.5 christos */
1112 1.5 christos switch (SourceOperandOp->Asl.ParseOpcode)
1113 1.5 christos {
1114 1.5 christos /* For these, type of the returned value is unknown at compile time */
1115 1.5 christos
1116 1.5 christos case PARSEOP_DEREFOF:
1117 1.5 christos case PARSEOP_METHODCALL:
1118 1.5 christos case PARSEOP_STORE:
1119 1.5 christos case PARSEOP_COPYOBJECT:
1120 1.5 christos
1121 1.5 christos return;
1122 1.5 christos
1123 1.5 christos case PARSEOP_INDEX:
1124 1.5 christos case PARSEOP_REFOF:
1125 1.5 christos
1126 1.11 christos if (!AslGbl_EnableReferenceTypechecking)
1127 1.5 christos {
1128 1.5 christos return;
1129 1.5 christos }
1130 1.5 christos
1131 1.5 christos /*
1132 1.5 christos * These opcodes always return an object reference, and thus
1133 1.5 christos * the result can only be stored to a Local, Arg, or Debug.
1134 1.5 christos */
1135 1.5 christos if (TargetOperandOp->Asl.AmlOpcode == AML_DEBUG_OP)
1136 1.5 christos {
1137 1.5 christos return;
1138 1.5 christos }
1139 1.5 christos
1140 1.5 christos if ((TargetOperandOp->Asl.AmlOpcode < AML_LOCAL0) ||
1141 1.5 christos (TargetOperandOp->Asl.AmlOpcode > AML_ARG6))
1142 1.5 christos {
1143 1.5 christos AslError (ASL_ERROR, ASL_MSG_INVALID_TYPE, TargetOperandOp,
1144 1.5 christos "Source [Reference], Target must be [Local/Arg/Debug]");
1145 1.5 christos }
1146 1.5 christos return;
1147 1.5 christos
1148 1.5 christos default:
1149 1.5 christos break;
1150 1.5 christos }
1151 1.5 christos
1152 1.5 christos /*
1153 1.5 christos * Ignore these Target operand opcodes, they cannot be typechecked
1154 1.5 christos */
1155 1.5 christos switch (TargetOperandOp->Asl.ParseOpcode)
1156 1.5 christos {
1157 1.5 christos case PARSEOP_DEBUG:
1158 1.5 christos case PARSEOP_DEREFOF:
1159 1.5 christos case PARSEOP_REFOF:
1160 1.5 christos case PARSEOP_INDEX:
1161 1.7 christos case PARSEOP_STORE:
1162 1.6 christos
1163 1.6 christos return;
1164 1.6 christos
1165 1.5 christos default:
1166 1.5 christos break;
1167 1.5 christos }
1168 1.5 christos
1169 1.5 christos /*
1170 1.5 christos * Ignore typecheck for External() operands of type "UnknownObj",
1171 1.5 christos * we don't know the actual type (source or target).
1172 1.5 christos */
1173 1.5 christos SourceNode = SourceOperandOp->Asl.Node;
1174 1.5 christos if (SourceNode &&
1175 1.5 christos (SourceNode->Flags & ANOBJ_IS_EXTERNAL) &&
1176 1.5 christos (SourceNode->Type == ACPI_TYPE_ANY))
1177 1.5 christos {
1178 1.5 christos return;
1179 1.5 christos }
1180 1.5 christos
1181 1.5 christos TargetNode = TargetOperandOp->Asl.Node;
1182 1.5 christos if (TargetNode &&
1183 1.5 christos (TargetNode->Flags & ANOBJ_IS_EXTERNAL) &&
1184 1.5 christos (TargetNode->Type == ACPI_TYPE_ANY))
1185 1.5 christos {
1186 1.5 christos return;
1187 1.5 christos }
1188 1.5 christos
1189 1.5 christos /*
1190 1.5 christos * A NULL node with a namepath AML opcode indicates non-existent
1191 1.5 christos * name. Just return, the error message is generated elsewhere.
1192 1.5 christos */
1193 1.5 christos if ((!SourceNode && (SourceOperandOp->Asl.AmlOpcode == AML_INT_NAMEPATH_OP)) ||
1194 1.5 christos (!TargetNode && (TargetOperandOp->Asl.AmlOpcode == AML_INT_NAMEPATH_OP)))
1195 1.5 christos {
1196 1.5 christos return;
1197 1.5 christos }
1198 1.5 christos
1199 1.5 christos /*
1200 1.5 christos * Simple check for source same as target via NS node.
1201 1.5 christos * -- Could be expanded to locals and args.
1202 1.5 christos */
1203 1.5 christos if (SourceNode && TargetNode)
1204 1.5 christos {
1205 1.5 christos if (SourceNode == TargetNode)
1206 1.5 christos {
1207 1.5 christos AslError (ASL_WARNING, ASL_MSG_DUPLICATE_ITEM,
1208 1.5 christos TargetOperandOp, "Source is the same as Target");
1209 1.5 christos return;
1210 1.5 christos }
1211 1.5 christos }
1212 1.5 christos
1213 1.5 christos /* Ignore typecheck if either source or target is a local or arg */
1214 1.5 christos
1215 1.5 christos if ((SourceOperandOp->Asl.AmlOpcode >= AML_LOCAL0) &&
1216 1.5 christos (SourceOperandOp->Asl.AmlOpcode <= AML_ARG6))
1217 1.5 christos {
1218 1.5 christos return; /* Cannot type a local/arg at compile time */
1219 1.5 christos }
1220 1.5 christos
1221 1.5 christos if ((TargetOperandOp->Asl.AmlOpcode >= AML_LOCAL0) &&
1222 1.5 christos (TargetOperandOp->Asl.AmlOpcode <= AML_ARG6))
1223 1.5 christos {
1224 1.5 christos return; /* Cannot type a local/arg at compile time */
1225 1.5 christos }
1226 1.5 christos
1227 1.5 christos /*
1228 1.5 christos * Package objects are a special case because they cannot by implicitly
1229 1.5 christos * converted to/from anything. Check for these two illegal cases:
1230 1.5 christos *
1231 1.5 christos * Store (non-package, package)
1232 1.5 christos * Store (package, non-package)
1233 1.5 christos */
1234 1.5 christos SourceOperandBtype = AnGetBtype (SourceOperandOp);
1235 1.5 christos TargetOperandBtype = AnGetBtype (TargetOperandOp);
1236 1.5 christos
1237 1.5 christos /* Check source first for (package, non-package) case */
1238 1.5 christos
1239 1.5 christos if (SourceOperandBtype & ACPI_BTYPE_PACKAGE)
1240 1.5 christos {
1241 1.5 christos /* If Source is PACKAGE-->Target must be PACKAGE */
1242 1.5 christos
1243 1.5 christos if (!(TargetOperandBtype & ACPI_BTYPE_PACKAGE))
1244 1.5 christos {
1245 1.5 christos AslError (ASL_ERROR, ASL_MSG_INVALID_TYPE, TargetOperandOp,
1246 1.5 christos "Source is [Package], Target must be a package also");
1247 1.5 christos }
1248 1.5 christos }
1249 1.5 christos
1250 1.5 christos /* Else check target for (non-package, package) case */
1251 1.5 christos
1252 1.5 christos else if (TargetOperandBtype & ACPI_BTYPE_PACKAGE)
1253 1.5 christos {
1254 1.5 christos /* If Target is PACKAGE, Source must be PACKAGE */
1255 1.5 christos
1256 1.5 christos if (!(SourceOperandBtype & ACPI_BTYPE_PACKAGE))
1257 1.5 christos {
1258 1.5 christos AslError (ASL_ERROR, ASL_MSG_INVALID_TYPE, SourceOperandOp,
1259 1.5 christos "Target is [Package], Source must be a package also");
1260 1.5 christos }
1261 1.5 christos }
1262 1.5 christos }
1263