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