psargs.c revision 91116
1/******************************************************************************
2 *
3 * Module Name: psargs - Parse AML opcode arguments
4 *              $Revision: 58 $
5 *
6 *****************************************************************************/
7
8/******************************************************************************
9 *
10 * 1. Copyright Notice
11 *
12 * Some or all of this work - Copyright (c) 1999 - 2002, Intel Corp.
13 * All rights reserved.
14 *
15 * 2. License
16 *
17 * 2.1. This is your license from Intel Corp. under its intellectual property
18 * rights.  You may have additional license terms from the party that provided
19 * you this software, covering your right to use that party's intellectual
20 * property rights.
21 *
22 * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
23 * copy of the source code appearing in this file ("Covered Code") an
24 * irrevocable, perpetual, worldwide license under Intel's copyrights in the
25 * base code distributed originally by Intel ("Original Intel Code") to copy,
26 * make derivatives, distribute, use and display any portion of the Covered
27 * Code in any form, with the right to sublicense such rights; and
28 *
29 * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
30 * license (with the right to sublicense), under only those claims of Intel
31 * patents that are infringed by the Original Intel Code, to make, use, sell,
32 * offer to sell, and import the Covered Code and derivative works thereof
33 * solely to the minimum extent necessary to exercise the above copyright
34 * license, and in no event shall the patent license extend to any additions
35 * to or modifications of the Original Intel Code.  No other license or right
36 * is granted directly or by implication, estoppel or otherwise;
37 *
38 * The above copyright and patent license is granted only if the following
39 * conditions are met:
40 *
41 * 3. Conditions
42 *
43 * 3.1. Redistribution of Source with Rights to Further Distribute Source.
44 * Redistribution of source code of any substantial portion of the Covered
45 * Code or modification with rights to further distribute source must include
46 * the above Copyright Notice, the above License, this list of Conditions,
47 * and the following Disclaimer and Export Compliance provision.  In addition,
48 * Licensee must cause all Covered Code to which Licensee contributes to
49 * contain a file documenting the changes Licensee made to create that Covered
50 * Code and the date of any change.  Licensee must include in that file the
51 * documentation of any changes made by any predecessor Licensee.  Licensee
52 * must include a prominent statement that the modification is derived,
53 * directly or indirectly, from Original Intel Code.
54 *
55 * 3.2. Redistribution of Source with no Rights to Further Distribute Source.
56 * Redistribution of source code of any substantial portion of the Covered
57 * Code or modification without rights to further distribute source must
58 * include the following Disclaimer and Export Compliance provision in the
59 * documentation and/or other materials provided with distribution.  In
60 * addition, Licensee may not authorize further sublicense of source of any
61 * portion of the Covered Code, and must include terms to the effect that the
62 * license from Licensee to its licensee is limited to the intellectual
63 * property embodied in the software Licensee provides to its licensee, and
64 * not to intellectual property embodied in modifications its licensee may
65 * make.
66 *
67 * 3.3. Redistribution of Executable. Redistribution in executable form of any
68 * substantial portion of the Covered Code or modification must reproduce the
69 * above Copyright Notice, and the following Disclaimer and Export Compliance
70 * provision in the documentation and/or other materials provided with the
71 * distribution.
72 *
73 * 3.4. Intel retains all right, title, and interest in and to the Original
74 * Intel Code.
75 *
76 * 3.5. Neither the name Intel nor any other trademark owned or controlled by
77 * Intel shall be used in advertising or otherwise to promote the sale, use or
78 * other dealings in products derived from or relating to the Covered Code
79 * without prior written authorization from Intel.
80 *
81 * 4. Disclaimer and Export Compliance
82 *
83 * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
84 * HERE.  ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
85 * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT,  ASSISTANCE,
86 * INSTALLATION, TRAINING OR OTHER SERVICES.  INTEL WILL NOT PROVIDE ANY
87 * UPDATES, ENHANCEMENTS OR EXTENSIONS.  INTEL SPECIFICALLY DISCLAIMS ANY
88 * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
89 * PARTICULAR PURPOSE.
90 *
91 * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
92 * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
93 * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
94 * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
95 * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
96 * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES.  THESE LIMITATIONS
97 * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
98 * LIMITED REMEDY.
99 *
100 * 4.3. Licensee shall not export, either directly or indirectly, any of this
101 * software or system incorporating such software without first obtaining any
102 * required license or other approval from the U. S. Department of Commerce or
103 * any other agency or department of the United States Government.  In the
104 * event Licensee exports any such software from the United States or
105 * re-exports any such software from a foreign destination, Licensee shall
106 * ensure that the distribution and export/re-export of the software is in
107 * compliance with all laws, regulations, orders, or other restrictions of the
108 * U.S. Export Administration Regulations. Licensee agrees that neither it nor
109 * any of its subsidiaries will export/re-export any technical data, process,
110 * software, or service, directly or indirectly, to any country for which the
111 * United States government or any agency thereof requires an export license,
112 * other governmental approval, or letter of assurance, without first obtaining
113 * such license, approval or letter.
114 *
115 *****************************************************************************/
116
117#define __PSARGS_C__
118
119#include "acpi.h"
120#include "acparser.h"
121#include "amlcode.h"
122#include "acnamesp.h"
123
124#define _COMPONENT          ACPI_PARSER
125        ACPI_MODULE_NAME    ("psargs")
126
127
128/*******************************************************************************
129 *
130 * FUNCTION:    AcpiPsGetNextPackageLength
131 *
132 * PARAMETERS:  ParserState         - Current parser state object
133 *
134 * RETURN:      Decoded package length.  On completion, the AML pointer points
135 *              past the length byte or bytes.
136 *
137 * DESCRIPTION: Decode and return a package length field
138 *
139 ******************************************************************************/
140
141UINT32
142AcpiPsGetNextPackageLength (
143    ACPI_PARSE_STATE        *ParserState)
144{
145    UINT32                  EncodedLength;
146    UINT32                  Length = 0;
147
148
149    ACPI_FUNCTION_TRACE ("PsGetNextPackageLength");
150
151
152    EncodedLength = (UINT32) ACPI_GET8 (ParserState->Aml);
153    ParserState->Aml++;
154
155
156    switch (EncodedLength >> 6) /* bits 6-7 contain encoding scheme */
157    {
158    case 0: /* 1-byte encoding (bits 0-5) */
159
160        Length = (EncodedLength & 0x3F);
161        break;
162
163
164    case 1: /* 2-byte encoding (next byte + bits 0-3) */
165
166        Length = ((ACPI_GET8 (ParserState->Aml) << 04) |
167                 (EncodedLength & 0x0F));
168        ParserState->Aml++;
169        break;
170
171
172    case 2: /* 3-byte encoding (next 2 bytes + bits 0-3) */
173
174        Length = ((ACPI_GET8 (ParserState->Aml + 1) << 12) |
175                  (ACPI_GET8 (ParserState->Aml)     << 04) |
176                  (EncodedLength & 0x0F));
177        ParserState->Aml += 2;
178        break;
179
180
181    case 3: /* 4-byte encoding (next 3 bytes + bits 0-3) */
182
183        Length = ((ACPI_GET8 (ParserState->Aml + 2) << 20) |
184                  (ACPI_GET8 (ParserState->Aml + 1) << 12) |
185                  (ACPI_GET8 (ParserState->Aml)     << 04) |
186                  (EncodedLength & 0x0F));
187        ParserState->Aml += 3;
188        break;
189    }
190
191    return_VALUE (Length);
192}
193
194
195/*******************************************************************************
196 *
197 * FUNCTION:    AcpiPsGetNextPackageEnd
198 *
199 * PARAMETERS:  ParserState         - Current parser state object
200 *
201 * RETURN:      Pointer to end-of-package +1
202 *
203 * DESCRIPTION: Get next package length and return a pointer past the end of
204 *              the package.  Consumes the package length field
205 *
206 ******************************************************************************/
207
208UINT8 *
209AcpiPsGetNextPackageEnd (
210    ACPI_PARSE_STATE        *ParserState)
211{
212    UINT8                   *Start = ParserState->Aml;
213    NATIVE_UINT             Length;
214
215
216    ACPI_FUNCTION_TRACE ("PsGetNextPackageEnd");
217
218
219    Length = (NATIVE_UINT) AcpiPsGetNextPackageLength (ParserState);
220
221    return_PTR (Start + Length); /* end of package */
222}
223
224
225/*******************************************************************************
226 *
227 * FUNCTION:    AcpiPsGetNextNamestring
228 *
229 * PARAMETERS:  ParserState         - Current parser state object
230 *
231 * RETURN:      Pointer to the start of the name string (pointer points into
232 *              the AML.
233 *
234 * DESCRIPTION: Get next raw namestring within the AML stream.  Handles all name
235 *              prefix characters.  Set parser state to point past the string.
236 *              (Name is consumed from the AML.)
237 *
238 ******************************************************************************/
239
240NATIVE_CHAR *
241AcpiPsGetNextNamestring (
242    ACPI_PARSE_STATE        *ParserState)
243{
244    UINT8                    *Start = ParserState->Aml;
245    UINT8                    *End = ParserState->Aml;
246    UINT32                  Length;
247
248
249    ACPI_FUNCTION_TRACE ("PsGetNextNamestring");
250
251
252    /* Handle multiple prefix characters */
253
254    while (AcpiPsIsPrefixChar (ACPI_GET8 (End)))
255    {
256        /* include prefix '\\' or '^' */
257
258        End++;
259    }
260
261    /* Decode the path */
262
263    switch (ACPI_GET8 (End))
264    {
265    case 0:
266
267        /* NullName */
268
269        if (End == Start)
270        {
271            Start = NULL;
272        }
273        End++;
274        break;
275
276
277    case AML_DUAL_NAME_PREFIX:
278
279        /* two name segments */
280
281        End += 9;
282        break;
283
284
285    case AML_MULTI_NAME_PREFIX_OP:
286
287        /* multiple name segments */
288
289        Length = (UINT32) ACPI_GET8 (End + 1) * 4;
290        End += 2 + Length;
291        break;
292
293
294    default:
295
296        /* single name segment */
297        /* assert (AcpiPsIsLead (GET8 (End))); */
298
299        End += 4;
300        break;
301    }
302
303    ParserState->Aml = (UINT8*) End;
304
305    return_PTR ((NATIVE_CHAR *) Start);
306}
307
308
309/*******************************************************************************
310 *
311 * FUNCTION:    AcpiPsGetNextNamepath
312 *
313 * PARAMETERS:  ParserState         - Current parser state object
314 *              Arg                 - Where the namepath will be stored
315 *              ArgCount            - If the namepath points to a control method
316 *                                    the method's argument is returned here.
317 *              MethodCall          - Whether the namepath can be the start
318 *                                    of a method call
319 *
320 * RETURN:      None
321 *
322 * DESCRIPTION: Get next name (if method call, push appropriate # args).  Names
323 *              are looked up in either the parsed or internal namespace to
324 *              determine if the name represents a control method.  If a method
325 *              is found, the number of arguments to the method is returned.
326 *              This information is critical for parsing to continue correctly.
327 *
328 ******************************************************************************/
329
330
331#ifdef PARSER_ONLY
332
333void
334AcpiPsGetNextNamepath (
335    ACPI_PARSE_STATE        *ParserState,
336    ACPI_PARSE_OBJECT       *Arg,
337    UINT32                  *ArgCount,
338    BOOLEAN                 MethodCall)
339{
340    NATIVE_CHAR             *Path;
341    ACPI_PARSE_OBJECT       *NameOp;
342    ACPI_PARSE_OBJECT       *Op;
343    ACPI_PARSE_OBJECT       *Count;
344
345
346    ACPI_FUNCTION_TRACE ("PsGetNextNamepath");
347
348
349    Path = AcpiPsGetNextNamestring (ParserState);
350    if (!Path || !MethodCall)
351    {
352        /* Null name case, create a null namepath object */
353
354        AcpiPsInitOp (Arg, AML_INT_NAMEPATH_OP);
355        Arg->Value.Name = Path;
356        return_VOID;
357    }
358
359
360    if (AcpiGbl_ParsedNamespaceRoot)
361    {
362        /*
363         * Lookup the name in the parsed namespace
364         */
365        Op = NULL;
366        if (MethodCall)
367        {
368            Op = AcpiPsFind (AcpiPsGetParentScope (ParserState),
369                                Path, AML_METHOD_OP, 0);
370        }
371
372        if (Op)
373        {
374            if (Op->Opcode == AML_METHOD_OP)
375            {
376                /*
377                 * The name refers to a control method, so this namepath is a
378                 * method invocation.  We need to 1) Get the number of arguments
379                 * associated with this method, and 2) Change the NAMEPATH
380                 * object into a METHODCALL object.
381                 */
382                Count = AcpiPsGetArg (Op, 0);
383                if (Count && Count->Opcode == AML_BYTE_OP)
384                {
385                    NameOp = AcpiPsAllocOp (AML_INT_NAMEPATH_OP);
386                    if (NameOp)
387                    {
388                        /* Change arg into a METHOD CALL and attach the name */
389
390                        AcpiPsInitOp (Arg, AML_INT_METHODCALL_OP);
391
392                        NameOp->Value.Name = Path;
393
394                        /* Point METHODCALL/NAME to the METHOD Node */
395
396                        NameOp->Node = (ACPI_NAMESPACE_NODE *) Op;
397                        AcpiPsAppendArg (Arg, NameOp);
398
399                        *ArgCount = (UINT32) Count->Value.Integer &
400                                    METHOD_FLAGS_ARG_COUNT;
401                    }
402                }
403
404                return_VOID;
405            }
406
407            /*
408             * Else this is normal named object reference.
409             * Just init the NAMEPATH object with the pathname.
410             * (See code below)
411             */
412        }
413    }
414
415    /*
416     * Either we didn't find the object in the namespace, or the object is
417     * something other than a control method.  Just initialize the Op with the
418     * pathname
419     */
420    AcpiPsInitOp (Arg, AML_INT_NAMEPATH_OP);
421    Arg->Value.Name = Path;
422
423
424    return_VOID;
425}
426
427
428#else
429
430
431void
432AcpiPsGetNextNamepath (
433    ACPI_PARSE_STATE        *ParserState,
434    ACPI_PARSE_OBJECT       *Arg,
435    UINT32                  *ArgCount,
436    BOOLEAN                 MethodCall)
437{
438    NATIVE_CHAR             *Path;
439    ACPI_PARSE_OBJECT       *NameOp;
440    ACPI_STATUS             Status;
441    ACPI_NAMESPACE_NODE     *MethodNode = NULL;
442    ACPI_NAMESPACE_NODE     *Node;
443    ACPI_GENERIC_STATE      ScopeInfo;
444
445
446    ACPI_FUNCTION_TRACE ("PsGetNextNamepath");
447
448
449    Path = AcpiPsGetNextNamestring (ParserState);
450    if (!Path || !MethodCall)
451    {
452        /* Null name case, create a null namepath object */
453
454        AcpiPsInitOp (Arg, AML_INT_NAMEPATH_OP);
455        Arg->Value.Name = Path;
456        return_VOID;
457    }
458
459
460    if (MethodCall)
461    {
462        /*
463         * Lookup the name in the internal namespace
464         */
465        ScopeInfo.Scope.Node = NULL;
466        Node = ParserState->StartNode;
467        if (Node)
468        {
469            ScopeInfo.Scope.Node = Node;
470        }
471
472        /*
473         * Lookup object.  We don't want to add anything new to the namespace
474         * here, however.  So we use MODE_EXECUTE.  Allow searching of the
475         * parent tree, but don't open a new scope -- we just want to lookup the
476         * object  (MUST BE mode EXECUTE to perform upsearch)
477         */
478        Status = AcpiNsLookup (&ScopeInfo, Path, ACPI_TYPE_ANY, ACPI_IMODE_EXECUTE,
479                                ACPI_NS_SEARCH_PARENT | ACPI_NS_DONT_OPEN_SCOPE, NULL,
480                                &Node);
481        if (ACPI_SUCCESS (Status))
482        {
483            if (Node->Type == ACPI_TYPE_METHOD)
484            {
485                MethodNode = Node;
486                ACPI_DEBUG_PRINT ((ACPI_DB_PARSE, "method - %p Path=%p\n",
487                    MethodNode, Path));
488
489                NameOp = AcpiPsAllocOp (AML_INT_NAMEPATH_OP);
490                if (NameOp)
491                {
492                    /* Change arg into a METHOD CALL and attach name to it */
493
494                    AcpiPsInitOp (Arg, AML_INT_METHODCALL_OP);
495
496                    NameOp->Value.Name = Path;
497
498                    /* Point METHODCALL/NAME to the METHOD Node */
499
500                    NameOp->Node = MethodNode;
501                    AcpiPsAppendArg (Arg, NameOp);
502
503                    if (!AcpiNsGetAttachedObject (MethodNode))
504                    {
505                        return_VOID;
506                    }
507
508                    *ArgCount = (AcpiNsGetAttachedObject (MethodNode))->Method.ParamCount;
509                }
510
511                return_VOID;
512            }
513
514            /*
515             * Else this is normal named object reference.
516             * Just init the NAMEPATH object with the pathname.
517             * (See code below)
518             */
519        }
520    }
521
522    /*
523     * Either we didn't find the object in the namespace, or the object is
524     * something other than a control method.  Just initialize the Op with the
525     * pathname.
526     */
527    AcpiPsInitOp (Arg, AML_INT_NAMEPATH_OP);
528    Arg->Value.Name = Path;
529
530
531    return_VOID;
532}
533
534#endif
535
536/*******************************************************************************
537 *
538 * FUNCTION:    AcpiPsGetNextSimpleArg
539 *
540 * PARAMETERS:  ParserState         - Current parser state object
541 *              ArgType             - The argument type (AML_*_ARG)
542 *              Arg                 - Where the argument is returned
543 *
544 * RETURN:      None
545 *
546 * DESCRIPTION: Get the next simple argument (constant, string, or namestring)
547 *
548 ******************************************************************************/
549
550void
551AcpiPsGetNextSimpleArg (
552    ACPI_PARSE_STATE        *ParserState,
553    UINT32                  ArgType,
554    ACPI_PARSE_OBJECT       *Arg)
555{
556
557    ACPI_FUNCTION_TRACE_U32 ("PsGetNextSimpleArg", ArgType);
558
559
560    switch (ArgType)
561    {
562
563    case ARGP_BYTEDATA:
564
565        AcpiPsInitOp (Arg, AML_BYTE_OP);
566        Arg->Value.Integer = (UINT32) ACPI_GET8 (ParserState->Aml);
567        ParserState->Aml++;
568        break;
569
570
571    case ARGP_WORDDATA:
572
573        AcpiPsInitOp (Arg, AML_WORD_OP);
574
575        /* Get 2 bytes from the AML stream */
576
577        ACPI_MOVE_UNALIGNED16_TO_32 (&Arg->Value.Integer, ParserState->Aml);
578        ParserState->Aml += 2;
579        break;
580
581
582    case ARGP_DWORDDATA:
583
584        AcpiPsInitOp (Arg, AML_DWORD_OP);
585
586        /* Get 4 bytes from the AML stream */
587
588        ACPI_MOVE_UNALIGNED32_TO_32 (&Arg->Value.Integer, ParserState->Aml);
589        ParserState->Aml += 4;
590        break;
591
592
593    case ARGP_QWORDDATA:
594
595        AcpiPsInitOp (Arg, AML_QWORD_OP);
596
597        /* Get 8 bytes from the AML stream */
598
599        ACPI_MOVE_UNALIGNED64_TO_64 (&Arg->Value.Integer, ParserState->Aml);
600        ParserState->Aml += 8;
601        break;
602
603
604    case ARGP_CHARLIST:
605
606        AcpiPsInitOp (Arg, AML_STRING_OP);
607        Arg->Value.String = (char *) ParserState->Aml;
608
609        while (ACPI_GET8 (ParserState->Aml) != '\0')
610        {
611            ParserState->Aml++;
612        }
613        ParserState->Aml++;
614        break;
615
616
617    case ARGP_NAME:
618    case ARGP_NAMESTRING:
619
620        AcpiPsInitOp (Arg, AML_INT_NAMEPATH_OP);
621        Arg->Value.Name = AcpiPsGetNextNamestring (ParserState);
622        break;
623    }
624
625    return_VOID;
626}
627
628
629/*******************************************************************************
630 *
631 * FUNCTION:    AcpiPsGetNextField
632 *
633 * PARAMETERS:  ParserState         - Current parser state object
634 *
635 * RETURN:      A newly allocated FIELD op
636 *
637 * DESCRIPTION: Get next field (NamedField, ReservedField, or AccessField)
638 *
639 ******************************************************************************/
640
641ACPI_PARSE_OBJECT *
642AcpiPsGetNextField (
643    ACPI_PARSE_STATE        *ParserState)
644{
645    UINT32                  AmlOffset = ParserState->Aml -
646                                        ParserState->AmlStart;
647    ACPI_PARSE_OBJECT       *Field;
648    UINT16                  Opcode;
649    UINT32                  Name;
650
651
652    ACPI_FUNCTION_TRACE ("PsGetNextField");
653
654
655    /* determine field type */
656
657    switch (ACPI_GET8 (ParserState->Aml))
658    {
659
660    default:
661
662        Opcode = AML_INT_NAMEDFIELD_OP;
663        break;
664
665
666    case 0x00:
667
668        Opcode = AML_INT_RESERVEDFIELD_OP;
669        ParserState->Aml++;
670        break;
671
672
673    case 0x01:
674
675        Opcode = AML_INT_ACCESSFIELD_OP;
676        ParserState->Aml++;
677        break;
678    }
679
680
681    /* Allocate a new field op */
682
683    Field = AcpiPsAllocOp (Opcode);
684    if (Field)
685    {
686        Field->AmlOffset = AmlOffset;
687
688        /* Decode the field type */
689
690        switch (Opcode)
691        {
692        case AML_INT_NAMEDFIELD_OP:
693
694            /* Get the 4-character name */
695
696            ACPI_MOVE_UNALIGNED32_TO_32 (&Name, ParserState->Aml);
697            AcpiPsSetName (Field, Name);
698            ParserState->Aml += 4;
699
700            /* Get the length which is encoded as a package length */
701
702            Field->Value.Size = AcpiPsGetNextPackageLength (ParserState);
703            break;
704
705
706        case AML_INT_RESERVEDFIELD_OP:
707
708            /* Get the length which is encoded as a package length */
709
710            Field->Value.Size = AcpiPsGetNextPackageLength (ParserState);
711            break;
712
713
714        case AML_INT_ACCESSFIELD_OP:
715
716            /*
717             * Get AccessType and AccessAttrib and merge into the field Op
718             * AccessType is first operand, AccessAttribute is second
719             */
720            Field->Value.Integer32 = (ACPI_GET8 (ParserState->Aml) << 8);
721            ParserState->Aml++;
722            Field->Value.Integer32 |= ACPI_GET8 (ParserState->Aml);
723            ParserState->Aml++;
724            break;
725        }
726    }
727
728    return_PTR (Field);
729}
730
731
732/*******************************************************************************
733 *
734 * FUNCTION:    AcpiPsGetNextArg
735 *
736 * PARAMETERS:  ParserState         - Current parser state object
737 *              ArgType             - The argument type (AML_*_ARG)
738 *              ArgCount            - If the argument points to a control method
739 *                                    the method's argument is returned here.
740 *
741 * RETURN:      An op object containing the next argument.
742 *
743 * DESCRIPTION: Get next argument (including complex list arguments that require
744 *              pushing the parser stack)
745 *
746 ******************************************************************************/
747
748ACPI_PARSE_OBJECT *
749AcpiPsGetNextArg (
750    ACPI_PARSE_STATE        *ParserState,
751    UINT32                  ArgType,
752    UINT32                  *ArgCount)
753{
754    ACPI_PARSE_OBJECT       *Arg = NULL;
755    ACPI_PARSE_OBJECT       *Prev = NULL;
756    ACPI_PARSE_OBJECT       *Field;
757    UINT32                  Subop;
758
759
760    ACPI_FUNCTION_TRACE_PTR ("PsGetNextArg", ParserState);
761
762
763    switch (ArgType)
764    {
765    case ARGP_BYTEDATA:
766    case ARGP_WORDDATA:
767    case ARGP_DWORDDATA:
768    case ARGP_CHARLIST:
769    case ARGP_NAME:
770    case ARGP_NAMESTRING:
771
772        /* constants, strings, and namestrings are all the same size */
773
774        Arg = AcpiPsAllocOp (AML_BYTE_OP);
775        if (Arg)
776        {
777            AcpiPsGetNextSimpleArg (ParserState, ArgType, Arg);
778        }
779        break;
780
781
782    case ARGP_PKGLENGTH:
783
784        /* package length, nothing returned */
785
786        ParserState->PkgEnd = AcpiPsGetNextPackageEnd (ParserState);
787        break;
788
789
790    case ARGP_FIELDLIST:
791
792        if (ParserState->Aml < ParserState->PkgEnd)
793        {
794            /* non-empty list */
795
796            while (ParserState->Aml < ParserState->PkgEnd)
797            {
798                Field = AcpiPsGetNextField (ParserState);
799                if (!Field)
800                {
801                    break;
802                }
803
804                if (Prev)
805                {
806                    Prev->Next = Field;
807                }
808
809                else
810                {
811                    Arg = Field;
812                }
813
814                Prev = Field;
815            }
816
817            /* skip to End of byte data */
818
819            ParserState->Aml = ParserState->PkgEnd;
820        }
821        break;
822
823
824    case ARGP_BYTELIST:
825
826        if (ParserState->Aml < ParserState->PkgEnd)
827        {
828            /* non-empty list */
829
830            Arg = AcpiPsAllocOp (AML_INT_BYTELIST_OP);
831            if (Arg)
832            {
833                /* fill in bytelist data */
834
835                Arg->Value.Size = (ParserState->PkgEnd - ParserState->Aml);
836                ((ACPI_PARSE2_OBJECT *) Arg)->Data = ParserState->Aml;
837            }
838
839            /* skip to End of byte data */
840
841            ParserState->Aml = ParserState->PkgEnd;
842        }
843        break;
844
845
846    case ARGP_TARGET:
847    case ARGP_SUPERNAME:
848    case ARGP_SIMPLENAME:
849        {
850            Subop = AcpiPsPeekOpcode (ParserState);
851            if (Subop == 0              ||
852                AcpiPsIsLeadingChar (Subop) ||
853                AcpiPsIsPrefixChar (Subop))
854            {
855                /* NullName or NameString */
856
857                Arg = AcpiPsAllocOp (AML_INT_NAMEPATH_OP);
858                if (Arg)
859                {
860                    AcpiPsGetNextNamepath (ParserState, Arg, ArgCount, 0);
861                }
862            }
863
864            else
865            {
866                /* single complex argument, nothing returned */
867
868                *ArgCount = 1;
869            }
870        }
871        break;
872
873
874    case ARGP_DATAOBJ:
875    case ARGP_TERMARG:
876
877        /* single complex argument, nothing returned */
878
879        *ArgCount = 1;
880        break;
881
882
883    case ARGP_DATAOBJLIST:
884    case ARGP_TERMLIST:
885    case ARGP_OBJLIST:
886
887        if (ParserState->Aml < ParserState->PkgEnd)
888        {
889            /* non-empty list of variable arguments, nothing returned */
890
891            *ArgCount = ACPI_VAR_ARGS;
892        }
893        break;
894    }
895
896    return_PTR (Arg);
897}
898