1 /******************************************************************************
2 *
3 * Module Name: aslexternal - ASL External opcode compiler support
4 *
5 *****************************************************************************/
6
7 /******************************************************************************
8 *
9 * 1. Copyright Notice
10 *
11 * Some or all of this work - Copyright (c) 1999 - 2026, 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 <contrib/dev/acpica/compiler/aslcompiler.h>
153 #include "aslcompiler.y.h"
154 #include <contrib/dev/acpica/include/acparser.h>
155 #include <contrib/dev/acpica/include/amlcode.h>
156 #include <contrib/dev/acpica/include/acnamesp.h>
157
158
159 #define _COMPONENT ACPI_COMPILER
160 ACPI_MODULE_NAME ("aslexternal")
161
162
163 /* Local prototypes */
164
165 static void
166 ExInsertArgCount (
167 ACPI_PARSE_OBJECT *Op);
168
169 static void
170 ExMoveExternals (
171 ACPI_PARSE_OBJECT *DefinitionBlockOp);
172
173 static void
174 ExRemoveOpFromTree (
175 ACPI_PARSE_OBJECT *Op);
176
177
178 /*******************************************************************************
179 *
180 * FUNCTION: ExDoExternal
181 *
182 * PARAMETERS: Op - Current Parse node
183 *
184 * RETURN: None
185 *
186 * DESCRIPTION: Add an External() definition to the global list. This list
187 * is used to generate External opcodes.
188 *
189 ******************************************************************************/
190
191 void
ExDoExternal(ACPI_PARSE_OBJECT * Op)192 ExDoExternal (
193 ACPI_PARSE_OBJECT *Op)
194 {
195 ACPI_PARSE_OBJECT *ListOp;
196 ACPI_PARSE_OBJECT *Prev;
197 ACPI_PARSE_OBJECT *Next;
198 ACPI_PARSE_OBJECT *ArgCountOp;
199 ACPI_PARSE_OBJECT *TypeOp;
200 ACPI_PARSE_OBJECT *ExternTypeOp = Op->Asl.Child->Asl.Next;
201 ACPI_PARSE_OBJECT *Existing;
202 ACPI_PARSE_OBJECT *NameOp = Op->Asl.Child;
203 ACPI_PARSE_OBJECT *ExistingNameOp;
204 UINT32 ExternType;
205 UINT8 ParamCount = ASL_EXTERNAL_METHOD_UNKNOWN_PARAMS;
206 UINT32 ParamTypes[ACPI_METHOD_NUM_ARGS];
207 char *NewPath = NULL;
208 char *ExistingPath;
209
210
211 ExternType = AnMapObjTypeToBtype (ExternTypeOp);
212 if (ExternType != ACPI_BTYPE_METHOD)
213 {
214 /*
215 * If this is not a method, it has zero parameters this local variable
216 * is used only for methods
217 */
218 ParamCount = 0;
219 }
220
221 /*
222 * The parser allows optional parameter return types regardless of the
223 * type. Check object type keyword emit error if optional parameter/return
224 * types exist.
225 *
226 * Check the parameter return type
227 */
228 TypeOp = ExternTypeOp->Asl.Next;
229 if (TypeOp->Asl.Child)
230 {
231 /* Ignore the return type for now. */
232
233 (void) MtProcessTypeOp (TypeOp->Asl.Child);
234 if (ExternType != ACPI_BTYPE_METHOD)
235 {
236 sprintf (AslGbl_MsgBuffer, "Found type [%s]", AcpiUtGetTypeName(ExternType));
237 AslError (ASL_ERROR, ASL_MSG_EXTERN_INVALID_RET_TYPE, TypeOp,
238 AslGbl_MsgBuffer);
239 }
240 }
241
242 /* Check the parameter types */
243
244 TypeOp = TypeOp->Asl.Next;
245 if (TypeOp->Asl.Child)
246 {
247 ParamCount = MtProcessParameterTypeList (TypeOp->Asl.Child, ParamTypes);
248 if (ExternType != ACPI_BTYPE_METHOD)
249 {
250 sprintf (AslGbl_MsgBuffer, "Found type [%s]", AcpiUtGetTypeName(ExternType));
251 AslError (ASL_ERROR, ASL_MSG_EXTERN_INVALID_PARAM_TYPE, TypeOp,
252 AslGbl_MsgBuffer);
253 }
254 }
255
256 ArgCountOp = Op->Asl.Child->Asl.Next->Asl.Next;
257 ArgCountOp->Asl.AmlOpcode = AML_RAW_DATA_BYTE;
258 ArgCountOp->Asl.ParseOpcode = PARSEOP_BYTECONST;
259 ArgCountOp->Asl.Value.Integer = ParamCount;
260 UtSetParseOpName (ArgCountOp);
261
262 /*
263 * Deduplicate identical External() declarations. The disassembler
264 * already collapses duplicates; mirror that behavior in the compiler
265 * so duplicate externals do not bloat emitted AML.
266 */
267
268 NewPath = NameOp->Asl.Namepath;
269 if (!NewPath && NameOp->Asl.Value.String)
270 {
271 (void) UtInternalizeName (NameOp->Asl.Value.String, &NewPath);
272 NameOp->Asl.Namepath = NewPath;
273 }
274
275 Existing = AslGbl_ExternalsListHead;
276 while (Existing && NewPath)
277 {
278 ExistingNameOp = Existing->Asl.Child->Asl.Child;
279 ExistingPath = ExistingNameOp->Asl.Namepath;
280 if (!ExistingPath && ExistingNameOp->Asl.Value.String)
281 {
282 (void) UtInternalizeName (ExistingNameOp->Asl.Value.String,
283 &ExistingPath);
284 ExistingNameOp->Asl.Namepath = ExistingPath;
285 }
286
287 if (ExistingPath && !strcmp (NewPath, ExistingPath))
288 {
289 ACPI_PARSE_OBJECT *ExistingArgCount;
290
291 /* Update arg count if this instance is more specific */
292
293 ExistingArgCount = Existing->Asl.Child->Asl.Child->Asl.Next->Asl.Next;
294 if ((ExternType == ACPI_BTYPE_METHOD) &&
295 (ParamCount < ExistingArgCount->Asl.Value.Integer))
296 {
297 ExistingArgCount->Asl.Value.Integer = ParamCount;
298 }
299
300 /* Remove duplicate External node from the parse tree */
301
302 ExRemoveOpFromTree (Op);
303 return;
304 }
305
306 Existing = Existing->Asl.Next;
307 }
308
309 /* Create new list node of arbitrary type */
310
311 ListOp = TrAllocateOp (PARSEOP_DEFAULT_ARG);
312
313 /* Store External node as child */
314
315 ListOp->Asl.Child = Op;
316 ListOp->Asl.Next = NULL;
317
318 if (AslGbl_ExternalsListHead)
319 {
320 /* Link new External to end of list */
321
322 Prev = AslGbl_ExternalsListHead;
323 Next = Prev;
324 while (Next)
325 {
326 Prev = Next;
327 Next = Next->Asl.Next;
328 }
329
330 Prev->Asl.Next = ListOp;
331 }
332 else
333 {
334 AslGbl_ExternalsListHead = ListOp;
335 }
336 }
337
338
339 /*******************************************************************************
340 *
341 * FUNCTION: ExRemoveOpFromTree
342 *
343 * PARAMETERS: Op - Parse op to remove from the tree
344 *
345 * RETURN: None
346 *
347 * DESCRIPTION: Unlink a parse op from its parent sibling list. Used to drop
348 * duplicate External() declarations before AML emission.
349 *
350 ******************************************************************************/
351
352 static void
ExRemoveOpFromTree(ACPI_PARSE_OBJECT * Op)353 ExRemoveOpFromTree (
354 ACPI_PARSE_OBJECT *Op)
355 {
356 ACPI_PARSE_OBJECT *Parent;
357 ACPI_PARSE_OBJECT *Child;
358
359
360 if (!Op || !Op->Asl.Parent)
361 {
362 return;
363 }
364
365 Parent = Op->Asl.Parent;
366 Child = Parent->Asl.Child;
367
368 if (Child == Op)
369 {
370 Parent->Asl.Child = Op->Asl.Next;
371 return;
372 }
373
374 while (Child && Child->Asl.Next != Op)
375 {
376 Child = Child->Asl.Next;
377 }
378
379 if (Child)
380 {
381 Child->Asl.Next = Op->Asl.Next;
382 }
383 }
384
385
386 /*******************************************************************************
387 *
388 * FUNCTION: ExInsertArgCount
389 *
390 * PARAMETERS: Op - Op for a method invocation
391 *
392 * RETURN: None
393 *
394 * DESCRIPTION: Obtain the number of arguments for a control method -- from
395 * the actual invocation.
396 *
397 ******************************************************************************/
398
399 static void
ExInsertArgCount(ACPI_PARSE_OBJECT * Op)400 ExInsertArgCount (
401 ACPI_PARSE_OBJECT *Op)
402 {
403 ACPI_PARSE_OBJECT *Next;
404 ACPI_PARSE_OBJECT *NameOp;
405 ACPI_PARSE_OBJECT *Child;
406 ACPI_PARSE_OBJECT *ArgCountOp;
407 char * ExternalName;
408 char * CallName;
409 UINT16 ArgCount = 0;
410 ACPI_STATUS Status;
411
412
413 CallName = AcpiNsGetNormalizedPathname (Op->Asl.Node, TRUE);
414
415 Next = AslGbl_ExternalsListHead;
416 while (Next)
417 {
418 ArgCount = 0;
419
420 /* Skip if External node already handled */
421
422 if (Next->Asl.Child->Asl.CompileFlags & OP_VISITED)
423 {
424 Next = Next->Asl.Next;
425 continue;
426 }
427
428 NameOp = Next->Asl.Child->Asl.Child;
429 ExternalName = AcpiNsGetNormalizedPathname (NameOp->Asl.Node, TRUE);
430
431 if (strcmp (CallName, ExternalName))
432 {
433 ACPI_FREE (ExternalName);
434 Next = Next->Asl.Next;
435 continue;
436 }
437
438 Next->Asl.Child->Asl.CompileFlags |= OP_VISITED;
439
440 /*
441 * Since we will reposition Externals to the Root, set Namepath
442 * to the fully qualified name and recalculate the aml length
443 */
444 Status = UtInternalizeName (ExternalName,
445 &NameOp->Asl.Value.String);
446
447 ACPI_FREE (ExternalName);
448 if (ACPI_FAILURE (Status))
449 {
450 AslError (ASL_ERROR, ASL_MSG_COMPILER_INTERNAL,
451 NULL, "- Could not Internalize External");
452 break;
453 }
454
455 NameOp->Asl.AmlLength = strlen (NameOp->Asl.Value.String);
456
457 /* Get argument count */
458
459 Child = Op->Asl.Child;
460 while (Child)
461 {
462 ArgCount++;
463 Child = Child->Asl.Next;
464 }
465
466 /* Setup ArgCount operand */
467
468 ArgCountOp = Next->Asl.Child->Asl.Child->Asl.Next->Asl.Next;
469 ArgCountOp->Asl.Value.Integer = ArgCount;
470 break;
471 }
472
473 ACPI_FREE (CallName);
474 }
475
476
477 /*******************************************************************************
478 *
479 * FUNCTION: ExAmlExternalWalkBegin
480 *
481 * PARAMETERS: ASL_WALK_CALLBACK
482 *
483 * RETURN: None
484 *
485 * DESCRIPTION: Parse tree walk to create external opcode list for methods.
486 *
487 ******************************************************************************/
488
489 ACPI_STATUS
ExAmlExternalWalkBegin(ACPI_PARSE_OBJECT * Op,UINT32 Level,void * Context)490 ExAmlExternalWalkBegin (
491 ACPI_PARSE_OBJECT *Op,
492 UINT32 Level,
493 void *Context)
494 {
495
496 /* External list head saved in the definition block op */
497
498 if (Op->Asl.ParseOpcode == PARSEOP_DEFINITION_BLOCK)
499 {
500 AslGbl_ExternalsListHead = Op->Asl.Value.Arg;
501 }
502
503 if (!AslGbl_ExternalsListHead)
504 {
505 return (AE_OK);
506 }
507
508 if (Op->Asl.ParseOpcode != PARSEOP_METHODCALL)
509 {
510 return (AE_OK);
511 }
512
513 /*
514 * The NameOp child under an ExternalOp gets turned into PARSE_METHODCALL
515 * by XfNamespaceLocateBegin(). Ignore these.
516 */
517 if (Op->Asl.Parent &&
518 Op->Asl.Parent->Asl.ParseOpcode == PARSEOP_EXTERNAL)
519 {
520 return (AE_OK);
521 }
522
523 ExInsertArgCount (Op);
524 return (AE_OK);
525 }
526
527
528 /*******************************************************************************
529 *
530 * FUNCTION: ExAmlExternalWalkEnd
531 *
532 * PARAMETERS: ASL_WALK_CALLBACK
533 *
534 * RETURN: None
535 *
536 * DESCRIPTION: Parse tree walk to create external opcode list for methods.
537 * Here, we just want to catch the case where a definition block
538 * has been completed. Then we move all of the externals into
539 * a single block in the parse tree and thus the AML code.
540 *
541 ******************************************************************************/
542
543 ACPI_STATUS
ExAmlExternalWalkEnd(ACPI_PARSE_OBJECT * Op,UINT32 Level,void * Context)544 ExAmlExternalWalkEnd (
545 ACPI_PARSE_OBJECT *Op,
546 UINT32 Level,
547 void *Context)
548 {
549
550 if (Op->Asl.ParseOpcode == PARSEOP_DEFINITION_BLOCK)
551 {
552 /*
553 * Process any existing external list. (Support for
554 * multiple definition blocks in a single file/compile)
555 */
556 ExMoveExternals (Op);
557 AslGbl_ExternalsListHead = NULL;
558 }
559
560 return (AE_OK);
561 }
562
563
564 /*******************************************************************************
565 *
566 * FUNCTION: ExMoveExternals
567 *
568 * PARAMETERS: DefinitionBlockOp - Op for current definition block
569 *
570 * RETURN: None
571 *
572 * DESCRIPTION: Move all externals present in the source file into a single
573 * block of AML code, surrounded by an "If (0)" to prevent
574 * AML interpreters from attempting to execute the External
575 * opcodes.
576 *
577 ******************************************************************************/
578
579 static void
ExMoveExternals(ACPI_PARSE_OBJECT * DefinitionBlockOp)580 ExMoveExternals (
581 ACPI_PARSE_OBJECT *DefinitionBlockOp)
582 {
583 ACPI_PARSE_OBJECT *ParentOp;
584 ACPI_PARSE_OBJECT *ExternalOp;
585 ACPI_PARSE_OBJECT *PredicateOp;
586 ACPI_PARSE_OBJECT *NextOp;
587 ACPI_PARSE_OBJECT *Prev;
588 ACPI_PARSE_OBJECT *Next;
589 char *ExternalName;
590 ACPI_OBJECT_TYPE ObjType;
591 ACPI_STATUS Status;
592 UINT32 i;
593
594
595 if (!AslGbl_ExternalsListHead)
596 {
597 return;
598 }
599
600 /* Remove the External nodes from the tree */
601
602 NextOp = AslGbl_ExternalsListHead;
603 while (NextOp)
604 {
605 /*
606 * The External is stored in child pointer of each node in the
607 * list
608 */
609 ExternalOp = NextOp->Asl.Child;
610
611 /* Get/set the fully qualified name */
612
613 ExternalName = AcpiNsGetNormalizedPathname (ExternalOp->Asl.Node, TRUE);
614 ExternalOp->Asl.ExternalName = ExternalName;
615 ExternalOp->Asl.Namepath = ExternalName;
616
617 /* Set line numbers (for listings, etc.) */
618
619 ExternalOp->Asl.LineNumber = 0;
620 ExternalOp->Asl.LogicalLineNumber = 0;
621
622 Next = ExternalOp->Asl.Child;
623 Next->Asl.LineNumber = 0;
624 Next->Asl.LogicalLineNumber = 0;
625
626 if (Next->Asl.ParseOpcode == PARSEOP_NAMESEG)
627 {
628 Next->Asl.ParseOpcode = PARSEOP_NAMESTRING;
629 }
630
631 Next->Asl.ExternalName = ExternalName;
632 Status = UtInternalizeName (ExternalName, &Next->Asl.Value.String);
633 if (ACPI_FAILURE (Status))
634 {
635 AslError (ASL_ERROR, ASL_MSG_COMPILER_INTERNAL,
636 Next, "Could not internalize namestring");
637 return;
638 }
639
640 Next->Asl.AmlLength = strlen (Next->Asl.Value.String);
641
642 Next = Next->Asl.Next;
643 Next->Asl.LineNumber = 0;
644 Next->Asl.LogicalLineNumber = 0;
645
646 Next = Next->Asl.Next;
647 Next->Asl.LineNumber = 0;
648 Next->Asl.LogicalLineNumber = 0;
649
650 Next = Next->Asl.Next;
651 Next->Asl.LineNumber = 0;
652 Next->Asl.LogicalLineNumber = 0;
653
654 ParentOp = ExternalOp->Asl.Parent;
655 Prev = Next = ParentOp->Asl.Child;
656
657 /* Now find the External node's position in parse tree */
658
659 while (Next != ExternalOp)
660 {
661 Prev = Next;
662 Next = Next->Asl.Next;
663 }
664
665 /* Remove the External from the parse tree */
666
667 if (Prev == ExternalOp)
668 {
669 /* External was the first child node */
670
671 ParentOp->Asl.Child = ExternalOp->Asl.Next;
672 }
673
674 Prev->Asl.Next = ExternalOp->Asl.Next;
675 ExternalOp->Asl.Next = NULL;
676 ExternalOp->Asl.Parent = AslGbl_ExternalsListHead;
677
678 /* Point the External to the next in the list */
679
680 if (NextOp->Asl.Next)
681 {
682 ExternalOp->Asl.Next = NextOp->Asl.Next->Asl.Child;
683 }
684
685 NextOp = NextOp->Asl.Next;
686 }
687
688 /*
689 * Loop again to remove MethodObj Externals for which
690 * a MethodCall was not found (dead external reference)
691 */
692 Prev = AslGbl_ExternalsListHead->Asl.Child;
693 Next = Prev;
694 while (Next)
695 {
696 ObjType = (ACPI_OBJECT_TYPE)
697 Next->Asl.Child->Asl.Next->Asl.Value.Integer;
698
699 if (ObjType == ACPI_TYPE_METHOD &&
700 !(Next->Asl.CompileFlags & OP_VISITED))
701 {
702 if (Next == Prev)
703 {
704 AslGbl_ExternalsListHead->Asl.Child = Next->Asl.Next;
705 Next->Asl.Next = NULL;
706 Prev = AslGbl_ExternalsListHead->Asl.Child;
707 Next = Prev;
708 continue;
709 }
710 else
711 {
712 Prev->Asl.Next = Next->Asl.Next;
713 Next->Asl.Next = NULL;
714 Next = Prev->Asl.Next;
715 continue;
716 }
717 }
718
719 Prev = Next;
720 Next = Next->Asl.Next;
721 }
722
723 /* If list is now empty, don't bother to make If (0) block */
724
725 if (!AslGbl_ExternalsListHead->Asl.Child)
726 {
727 return;
728 }
729
730 /* Convert Gbl_ExternalsListHead parent to If(). */
731
732 AslGbl_ExternalsListHead->Asl.ParseOpcode = PARSEOP_IF;
733 AslGbl_ExternalsListHead->Asl.AmlOpcode = AML_IF_OP;
734 AslGbl_ExternalsListHead->Asl.CompileFlags = OP_AML_PACKAGE;
735 UtSetParseOpName (AslGbl_ExternalsListHead);
736
737 /* Create a Zero op for the If predicate */
738
739 PredicateOp = TrAllocateOp (PARSEOP_ZERO);
740 PredicateOp->Asl.AmlOpcode = AML_ZERO_OP;
741
742 PredicateOp->Asl.Parent = AslGbl_ExternalsListHead;
743 PredicateOp->Asl.Child = NULL;
744 PredicateOp->Asl.Next = AslGbl_ExternalsListHead->Asl.Child;
745 AslGbl_ExternalsListHead->Asl.Child = PredicateOp;
746
747 /* Set line numbers (for listings, etc.) */
748
749 AslGbl_ExternalsListHead->Asl.LineNumber = 0;
750 AslGbl_ExternalsListHead->Asl.LogicalLineNumber = 0;
751
752 PredicateOp->Asl.LineNumber = 0;
753 PredicateOp->Asl.LogicalLineNumber = 0;
754
755 /* Insert block back in the list */
756
757 Prev = DefinitionBlockOp->Asl.Child;
758 Next = Prev;
759
760 /* Find last default arg */
761
762 for (i = 0; i < 6; i++)
763 {
764 Prev = Next;
765 Next = Prev->Asl.Next;
766 }
767
768 if (Next)
769 {
770 /* Definition Block is not empty */
771
772 AslGbl_ExternalsListHead->Asl.Next = Next;
773 }
774 else
775 {
776 /* Definition Block is empty. */
777
778 AslGbl_ExternalsListHead->Asl.Next = NULL;
779 }
780
781 Prev->Asl.Next = AslGbl_ExternalsListHead;
782 AslGbl_ExternalsListHead->Asl.Parent = Prev->Asl.Parent;
783 }
784