1 /******************************************************************************
3 * Module Name: psobject - Support for parse objects
5 *****************************************************************************/
7 /******************************************************************************
11 * Some or all of this work - Copyright (c) 1999 - 2015, Intel Corp.
12 * All rights reserved.
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
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
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;
37 * The above copyright and patent license is granted only if the following
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.
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
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
72 * 3.4. Intel retains all right, title, and interest in and to the Original
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.
80 * 4. Disclaimer and Export Compliance
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
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
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.
114 *****************************************************************************/
117 #include "accommon.h"
118 #include "acparser.h"
121 #define _COMPONENT ACPI_PARSER
122 ACPI_MODULE_NAME ("psobject")
125 /* Local prototypes */
129 ACPI_WALK_STATE
*WalkState
);
132 /*******************************************************************************
134 * FUNCTION: AcpiPsGetAmlOpcode
136 * PARAMETERS: WalkState - Current state
140 * DESCRIPTION: Extract the next AML opcode from the input stream.
142 ******************************************************************************/
146 ACPI_WALK_STATE
*WalkState
)
151 ACPI_FUNCTION_TRACE_PTR (PsGetAmlOpcode
, WalkState
);
154 WalkState
->Aml
= WalkState
->ParserState
.Aml
;
155 WalkState
->Opcode
= AcpiPsPeekOpcode (&(WalkState
->ParserState
));
158 * First cut to determine what we have found:
159 * 1) A valid AML opcode
161 * 3) An unknown/invalid opcode
163 WalkState
->OpInfo
= AcpiPsGetOpcodeInfo (WalkState
->Opcode
);
165 switch (WalkState
->OpInfo
->Class
)
167 case AML_CLASS_ASCII
:
168 case AML_CLASS_PREFIX
:
170 * Starts with a valid prefix or ASCII char, this is a name
171 * string. Convert the bare name string to a namepath.
173 WalkState
->Opcode
= AML_INT_NAMEPATH_OP
;
174 WalkState
->ArgTypes
= ARGP_NAMESTRING
;
177 case AML_CLASS_UNKNOWN
:
179 /* The opcode is unrecognized. Complain and skip unknown opcodes */
181 if (WalkState
->PassNumber
== 2)
183 AmlOffset
= (UINT32
) ACPI_PTR_DIFF (WalkState
->Aml
,
184 WalkState
->ParserState
.AmlStart
);
186 ACPI_ERROR ((AE_INFO
,
187 "Unknown opcode 0x%.2X at table offset 0x%.4X, ignoring",
189 (UINT32
) (AmlOffset
+ sizeof (ACPI_TABLE_HEADER
))));
191 ACPI_DUMP_BUFFER ((WalkState
->ParserState
.Aml
- 16), 48);
193 #ifdef ACPI_ASL_COMPILER
195 * This is executed for the disassembler only. Output goes
196 * to the disassembled ASL output file.
199 "/*\nError: Unknown opcode 0x%.2X at table offset 0x%.4X, context:\n",
201 (UINT32
) (AmlOffset
+ sizeof (ACPI_TABLE_HEADER
)));
203 /* Dump the context surrounding the invalid opcode */
205 AcpiUtDumpBuffer (((UINT8
*) WalkState
->ParserState
.Aml
- 16),
207 (AmlOffset
+ sizeof (ACPI_TABLE_HEADER
) - 16));
208 AcpiOsPrintf (" */\n");
212 /* Increment past one-byte or two-byte opcode */
214 WalkState
->ParserState
.Aml
++;
215 if (WalkState
->Opcode
> 0xFF) /* Can only happen if first byte is 0x5B */
217 WalkState
->ParserState
.Aml
++;
220 return_ACPI_STATUS (AE_CTRL_PARSE_CONTINUE
);
224 /* Found opcode info, this is a normal opcode */
226 WalkState
->ParserState
.Aml
+=
227 AcpiPsGetOpcodeSize (WalkState
->Opcode
);
228 WalkState
->ArgTypes
= WalkState
->OpInfo
->ParseArgs
;
232 return_ACPI_STATUS (AE_OK
);
236 /*******************************************************************************
238 * FUNCTION: AcpiPsBuildNamedOp
240 * PARAMETERS: WalkState - Current state
241 * AmlOpStart - Begin of named Op in AML
242 * UnnamedOp - Early Op (not a named Op)
247 * DESCRIPTION: Parse a named Op
249 ******************************************************************************/
253 ACPI_WALK_STATE
*WalkState
,
255 ACPI_PARSE_OBJECT
*UnnamedOp
,
256 ACPI_PARSE_OBJECT
**Op
)
258 ACPI_STATUS Status
= AE_OK
;
259 ACPI_PARSE_OBJECT
*Arg
= NULL
;
262 ACPI_FUNCTION_TRACE_PTR (PsBuildNamedOp
, WalkState
);
265 UnnamedOp
->Common
.Value
.Arg
= NULL
;
266 UnnamedOp
->Common
.ArgListLength
= 0;
267 UnnamedOp
->Common
.AmlOpcode
= WalkState
->Opcode
;
270 * Get and append arguments until we find the node that contains
271 * the name (the type ARGP_NAME).
273 while (GET_CURRENT_ARG_TYPE (WalkState
->ArgTypes
) &&
274 (GET_CURRENT_ARG_TYPE (WalkState
->ArgTypes
) != ARGP_NAME
))
276 Status
= AcpiPsGetNextArg (WalkState
, &(WalkState
->ParserState
),
277 GET_CURRENT_ARG_TYPE (WalkState
->ArgTypes
), &Arg
);
278 if (ACPI_FAILURE (Status
))
280 return_ACPI_STATUS (Status
);
283 AcpiPsAppendArg (UnnamedOp
, Arg
);
284 INCREMENT_ARG_LIST (WalkState
->ArgTypes
);
288 * Make sure that we found a NAME and didn't run out of arguments
290 if (!GET_CURRENT_ARG_TYPE (WalkState
->ArgTypes
))
292 return_ACPI_STATUS (AE_AML_NO_OPERAND
);
295 /* We know that this arg is a name, move to next arg */
297 INCREMENT_ARG_LIST (WalkState
->ArgTypes
);
300 * Find the object. This will either insert the object into
301 * the namespace or simply look it up
303 WalkState
->Op
= NULL
;
305 Status
= WalkState
->DescendingCallback (WalkState
, Op
);
306 if (ACPI_FAILURE (Status
))
308 if (Status
!= AE_CTRL_TERMINATE
)
310 ACPI_EXCEPTION ((AE_INFO
, Status
, "During name lookup/catalog"));
312 return_ACPI_STATUS (Status
);
317 return_ACPI_STATUS (AE_CTRL_PARSE_CONTINUE
);
320 Status
= AcpiPsNextParseState (WalkState
, *Op
, Status
);
321 if (ACPI_FAILURE (Status
))
323 if (Status
== AE_CTRL_PENDING
)
325 Status
= AE_CTRL_PARSE_PENDING
;
327 return_ACPI_STATUS (Status
);
330 AcpiPsAppendArg (*Op
, UnnamedOp
->Common
.Value
.Arg
);
332 if ((*Op
)->Common
.AmlOpcode
== AML_REGION_OP
||
333 (*Op
)->Common
.AmlOpcode
== AML_DATA_REGION_OP
)
336 * Defer final parsing of an OperationRegion body, because we don't
337 * have enough info in the first pass to parse it correctly (i.e.,
338 * there may be method calls within the TermArg elements of the body.)
340 * However, we must continue parsing because the opregion is not a
341 * standalone package -- we don't know where the end is at this point.
343 * (Length is unknown until parse of the body complete)
345 (*Op
)->Named
.Data
= AmlOpStart
;
346 (*Op
)->Named
.Length
= 0;
349 return_ACPI_STATUS (AE_OK
);
353 /*******************************************************************************
355 * FUNCTION: AcpiPsCreateOp
357 * PARAMETERS: WalkState - Current state
358 * AmlOpStart - Op start in AML
359 * NewOp - Returned Op
363 * DESCRIPTION: Get Op from AML
365 ******************************************************************************/
369 ACPI_WALK_STATE
*WalkState
,
371 ACPI_PARSE_OBJECT
**NewOp
)
373 ACPI_STATUS Status
= AE_OK
;
374 ACPI_PARSE_OBJECT
*Op
;
375 ACPI_PARSE_OBJECT
*NamedOp
= NULL
;
376 ACPI_PARSE_OBJECT
*ParentScope
;
378 const ACPI_OPCODE_INFO
*OpInfo
;
381 ACPI_FUNCTION_TRACE_PTR (PsCreateOp
, WalkState
);
384 Status
= AcpiPsGetAmlOpcode (WalkState
);
385 if (Status
== AE_CTRL_PARSE_CONTINUE
)
387 return_ACPI_STATUS (AE_CTRL_PARSE_CONTINUE
);
390 /* Create Op structure and append to parent's argument list */
392 WalkState
->OpInfo
= AcpiPsGetOpcodeInfo (WalkState
->Opcode
);
393 Op
= AcpiPsAllocOp (WalkState
->Opcode
, AmlOpStart
);
396 return_ACPI_STATUS (AE_NO_MEMORY
);
399 if (WalkState
->OpInfo
->Flags
& AML_NAMED
)
401 Status
= AcpiPsBuildNamedOp (WalkState
, AmlOpStart
, Op
, &NamedOp
);
403 if (ACPI_FAILURE (Status
))
405 return_ACPI_STATUS (Status
);
409 return_ACPI_STATUS (AE_OK
);
412 /* Not a named opcode, just allocate Op and append to parent */
414 if (WalkState
->OpInfo
->Flags
& AML_CREATE
)
417 * Backup to beginning of CreateXXXfield declaration
418 * BodyLength is unknown until we parse the body
420 Op
->Named
.Data
= AmlOpStart
;
421 Op
->Named
.Length
= 0;
424 if (WalkState
->Opcode
== AML_BANK_FIELD_OP
)
427 * Backup to beginning of BankField declaration
428 * BodyLength is unknown until we parse the body
430 Op
->Named
.Data
= AmlOpStart
;
431 Op
->Named
.Length
= 0;
434 ParentScope
= AcpiPsGetParentScope (&(WalkState
->ParserState
));
435 AcpiPsAppendArg (ParentScope
, Op
);
439 OpInfo
= AcpiPsGetOpcodeInfo (ParentScope
->Common
.AmlOpcode
);
440 if (OpInfo
->Flags
& AML_HAS_TARGET
)
442 ArgumentCount
= AcpiPsGetArgumentCount (OpInfo
->Type
);
443 if (ParentScope
->Common
.ArgListLength
> ArgumentCount
)
445 Op
->Common
.Flags
|= ACPI_PARSEOP_TARGET
;
448 else if (ParentScope
->Common
.AmlOpcode
== AML_INCREMENT_OP
)
450 Op
->Common
.Flags
|= ACPI_PARSEOP_TARGET
;
454 if (WalkState
->DescendingCallback
!= NULL
)
457 * Find the object. This will either insert the object into
458 * the namespace or simply look it up
460 WalkState
->Op
= *NewOp
= Op
;
462 Status
= WalkState
->DescendingCallback (WalkState
, &Op
);
463 Status
= AcpiPsNextParseState (WalkState
, Op
, Status
);
464 if (Status
== AE_CTRL_PENDING
)
466 Status
= AE_CTRL_PARSE_PENDING
;
470 return_ACPI_STATUS (Status
);
474 /*******************************************************************************
476 * FUNCTION: AcpiPsCompleteOp
478 * PARAMETERS: WalkState - Current state
480 * Status - Parse status before complete Op
484 * DESCRIPTION: Complete Op
486 ******************************************************************************/
490 ACPI_WALK_STATE
*WalkState
,
491 ACPI_PARSE_OBJECT
**Op
,
497 ACPI_FUNCTION_TRACE_PTR (PsCompleteOp
, WalkState
);
501 * Finished one argument of the containing scope
503 WalkState
->ParserState
.Scope
->ParseScope
.ArgCount
--;
505 /* Close this Op (will result in parse subtree deletion) */
507 Status2
= AcpiPsCompleteThisOp (WalkState
, *Op
);
508 if (ACPI_FAILURE (Status2
))
510 return_ACPI_STATUS (Status2
);
521 case AE_CTRL_TRANSFER
:
523 /* We are about to transfer to a called method */
525 WalkState
->PrevOp
= NULL
;
526 WalkState
->PrevArgTypes
= WalkState
->ArgTypes
;
527 return_ACPI_STATUS (Status
);
531 AcpiPsPopScope (&(WalkState
->ParserState
), Op
,
532 &WalkState
->ArgTypes
, &WalkState
->ArgCount
);
537 WalkState
->OpInfo
= AcpiPsGetOpcodeInfo ((*Op
)->Common
.AmlOpcode
);
538 WalkState
->Opcode
= (*Op
)->Common
.AmlOpcode
;
540 Status
= WalkState
->AscendingCallback (WalkState
);
541 Status
= AcpiPsNextParseState (WalkState
, *Op
, Status
);
543 Status2
= AcpiPsCompleteThisOp (WalkState
, *Op
);
544 if (ACPI_FAILURE (Status2
))
546 return_ACPI_STATUS (Status2
);
554 case AE_CTRL_CONTINUE
:
556 /* Pop off scopes until we find the While */
558 while (!(*Op
) || ((*Op
)->Common
.AmlOpcode
!= AML_WHILE_OP
))
560 AcpiPsPopScope (&(WalkState
->ParserState
), Op
,
561 &WalkState
->ArgTypes
, &WalkState
->ArgCount
);
564 /* Close this iteration of the While loop */
567 WalkState
->OpInfo
= AcpiPsGetOpcodeInfo ((*Op
)->Common
.AmlOpcode
);
568 WalkState
->Opcode
= (*Op
)->Common
.AmlOpcode
;
570 Status
= WalkState
->AscendingCallback (WalkState
);
571 Status
= AcpiPsNextParseState (WalkState
, *Op
, Status
);
573 Status2
= AcpiPsCompleteThisOp (WalkState
, *Op
);
574 if (ACPI_FAILURE (Status2
))
576 return_ACPI_STATUS (Status2
);
582 case AE_CTRL_TERMINATE
:
589 Status2
= AcpiPsCompleteThisOp (WalkState
, *Op
);
590 if (ACPI_FAILURE (Status2
))
592 return_ACPI_STATUS (Status2
);
595 AcpiUtDeleteGenericState (
596 AcpiUtPopGenericState (&WalkState
->ControlState
));
599 AcpiPsPopScope (&(WalkState
->ParserState
), Op
,
600 &WalkState
->ArgTypes
, &WalkState
->ArgCount
);
604 return_ACPI_STATUS (AE_OK
);
606 default: /* All other non-AE_OK status */
612 Status2
= AcpiPsCompleteThisOp (WalkState
, *Op
);
613 if (ACPI_FAILURE (Status2
))
615 return_ACPI_STATUS (Status2
);
619 AcpiPsPopScope (&(WalkState
->ParserState
), Op
,
620 &WalkState
->ArgTypes
, &WalkState
->ArgCount
);
627 * TBD: Cleanup parse ops on error
631 AcpiPsPopScope (ParserState
, Op
,
632 &WalkState
->ArgTypes
, &WalkState
->ArgCount
);
635 WalkState
->PrevOp
= NULL
;
636 WalkState
->PrevArgTypes
= WalkState
->ArgTypes
;
637 return_ACPI_STATUS (Status
);
640 /* This scope complete? */
642 if (AcpiPsHasCompletedScope (&(WalkState
->ParserState
)))
644 AcpiPsPopScope (&(WalkState
->ParserState
), Op
,
645 &WalkState
->ArgTypes
, &WalkState
->ArgCount
);
646 ACPI_DEBUG_PRINT ((ACPI_DB_PARSE
, "Popped scope, Op=%p\n", *Op
));
653 return_ACPI_STATUS (AE_OK
);
657 /*******************************************************************************
659 * FUNCTION: AcpiPsCompleteFinalOp
661 * PARAMETERS: WalkState - Current state
663 * Status - Current parse status before complete last
668 * DESCRIPTION: Complete last Op.
670 ******************************************************************************/
673 AcpiPsCompleteFinalOp (
674 ACPI_WALK_STATE
*WalkState
,
675 ACPI_PARSE_OBJECT
*Op
,
681 ACPI_FUNCTION_TRACE_PTR (PsCompleteFinalOp
, WalkState
);
685 * Complete the last Op (if not completed), and clear the scope stack.
686 * It is easily possible to end an AML "package" with an unbounded number
687 * of open scopes (such as when several ASL blocks are closed with
688 * sequential closing braces). We want to terminate each one cleanly.
690 ACPI_DEBUG_PRINT ((ACPI_DB_PARSE
, "AML package complete at Op %p\n", Op
));
695 if (WalkState
->AscendingCallback
!= NULL
)
698 WalkState
->OpInfo
= AcpiPsGetOpcodeInfo (Op
->Common
.AmlOpcode
);
699 WalkState
->Opcode
= Op
->Common
.AmlOpcode
;
701 Status
= WalkState
->AscendingCallback (WalkState
);
702 Status
= AcpiPsNextParseState (WalkState
, Op
, Status
);
703 if (Status
== AE_CTRL_PENDING
)
705 Status
= AcpiPsCompleteOp (WalkState
, &Op
, AE_OK
);
706 if (ACPI_FAILURE (Status
))
708 return_ACPI_STATUS (Status
);
712 if (Status
== AE_CTRL_TERMINATE
)
721 Status2
= AcpiPsCompleteThisOp (WalkState
, Op
);
722 if (ACPI_FAILURE (Status2
))
724 return_ACPI_STATUS (Status2
);
728 AcpiPsPopScope (&(WalkState
->ParserState
), &Op
,
729 &WalkState
->ArgTypes
, &WalkState
->ArgCount
);
733 return_ACPI_STATUS (Status
);
736 else if (ACPI_FAILURE (Status
))
738 /* First error is most important */
740 (void) AcpiPsCompleteThisOp (WalkState
, Op
);
741 return_ACPI_STATUS (Status
);
745 Status2
= AcpiPsCompleteThisOp (WalkState
, Op
);
746 if (ACPI_FAILURE (Status2
))
748 return_ACPI_STATUS (Status2
);
752 AcpiPsPopScope (&(WalkState
->ParserState
), &Op
, &WalkState
->ArgTypes
,
753 &WalkState
->ArgCount
);
757 return_ACPI_STATUS (Status
);