asltransform.c revision 1.1.1.9.2.2 1 /******************************************************************************
2 *
3 * Module Name: asltransform - Parse tree transforms
4 *
5 *****************************************************************************/
6
7 /*
8 * Copyright (C) 2000 - 2018, Intel Corp.
9 * All rights reserved.
10 *
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
13 * are met:
14 * 1. Redistributions of source code must retain the above copyright
15 * notice, this list of conditions, and the following disclaimer,
16 * without modification.
17 * 2. Redistributions in binary form must reproduce at minimum a disclaimer
18 * substantially similar to the "NO WARRANTY" disclaimer below
19 * ("Disclaimer") and any redistribution must be conditioned upon
20 * including a substantially similar Disclaimer requirement for further
21 * binary redistribution.
22 * 3. Neither the names of the above-listed copyright holders nor the names
23 * of any contributors may be used to endorse or promote products derived
24 * from this software without specific prior written permission.
25 *
26 * Alternatively, this software may be distributed under the terms of the
27 * GNU General Public License ("GPL") version 2 as published by the Free
28 * Software Foundation.
29 *
30 * NO WARRANTY
31 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
32 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
33 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
34 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
35 * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
36 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
37 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
38 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
39 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
40 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
41 * POSSIBILITY OF SUCH DAMAGES.
42 */
43
44 #include "aslcompiler.h"
45 #include "aslcompiler.y.h"
46
47 #define _COMPONENT ACPI_COMPILER
48 ACPI_MODULE_NAME ("asltransform")
49
50 /* Local prototypes */
51
52 static void
53 TrTransformSubtree (
54 ACPI_PARSE_OBJECT *Op);
55
56 static char *
57 TrAmlGetNextTempName (
58 ACPI_PARSE_OBJECT *Op,
59 UINT8 *TempCount);
60
61 static void
62 TrAmlInitLineNumbers (
63 ACPI_PARSE_OBJECT *Op,
64 ACPI_PARSE_OBJECT *Neighbor);
65
66 static void
67 TrAmlInitNode (
68 ACPI_PARSE_OBJECT *Op,
69 UINT16 ParseOpcode);
70
71 static void
72 TrAmlSetSubtreeParent (
73 ACPI_PARSE_OBJECT *Op,
74 ACPI_PARSE_OBJECT *Parent);
75
76 static void
77 TrAmlInsertPeer (
78 ACPI_PARSE_OBJECT *Op,
79 ACPI_PARSE_OBJECT *NewPeer);
80
81 static void
82 TrDoDefinitionBlock (
83 ACPI_PARSE_OBJECT *Op);
84
85 static void
86 TrDoSwitch (
87 ACPI_PARSE_OBJECT *StartNode);
88
89
90 /*******************************************************************************
91 *
92 * FUNCTION: TrAmlGetNextTempName
93 *
94 * PARAMETERS: Op - Current parse op
95 * TempCount - Current temporary counter. Was originally
96 * per-module; Currently per method, could be
97 * expanded to per-scope.
98 *
99 * RETURN: A pointer to name (allocated here).
100 *
101 * DESCRIPTION: Generate an ACPI name of the form _T_x. These names are
102 * reserved for use by the ASL compiler. (_T_0 through _T_Z)
103 *
104 ******************************************************************************/
105
106 static char *
107 TrAmlGetNextTempName (
108 ACPI_PARSE_OBJECT *Op,
109 UINT8 *TempCount)
110 {
111 char *TempName;
112
113
114 if (*TempCount >= (10 + 26)) /* 0-35 valid: 0-9 and A-Z for TempName[3] */
115 {
116 /* Too many temps */
117
118 AslError (ASL_ERROR, ASL_MSG_TOO_MANY_TEMPS, Op, NULL);
119 return (NULL);
120 }
121
122 TempName = UtLocalCalloc (5);
123
124 if (*TempCount < 10) /* 0-9 */
125 {
126 TempName[3] = (char) (*TempCount + '0');
127 }
128 else /* 10-35: A-Z */
129 {
130 TempName[3] = (char) (*TempCount + ('A' - 10));
131 }
132
133 (*TempCount)++;
134
135 /* First three characters are always "_T_" */
136
137 TempName[0] = '_';
138 TempName[1] = 'T';
139 TempName[2] = '_';
140
141 return (TempName);
142 }
143
144
145 /*******************************************************************************
146 *
147 * FUNCTION: TrAmlInitLineNumbers
148 *
149 * PARAMETERS: Op - Op to be initialized
150 * Neighbor - Op used for initialization values
151 *
152 * RETURN: None
153 *
154 * DESCRIPTION: Initialized the various line numbers for a parse node.
155 *
156 ******************************************************************************/
157
158 static void
159 TrAmlInitLineNumbers (
160 ACPI_PARSE_OBJECT *Op,
161 ACPI_PARSE_OBJECT *Neighbor)
162 {
163
164 Op->Asl.EndLine = Neighbor->Asl.EndLine;
165 Op->Asl.EndLogicalLine = Neighbor->Asl.EndLogicalLine;
166 Op->Asl.LineNumber = Neighbor->Asl.LineNumber;
167 Op->Asl.LogicalByteOffset = Neighbor->Asl.LogicalByteOffset;
168 Op->Asl.LogicalLineNumber = Neighbor->Asl.LogicalLineNumber;
169 }
170
171
172 /*******************************************************************************
173 *
174 * FUNCTION: TrAmlInitNode
175 *
176 * PARAMETERS: Op - Op to be initialized
177 * ParseOpcode - Opcode for this node
178 *
179 * RETURN: None
180 *
181 * DESCRIPTION: Initialize a node with the parse opcode and opcode name.
182 *
183 ******************************************************************************/
184
185 static void
186 TrAmlInitNode (
187 ACPI_PARSE_OBJECT *Op,
188 UINT16 ParseOpcode)
189 {
190
191 Op->Asl.ParseOpcode = ParseOpcode;
192 UtSetParseOpName (Op);
193 }
194
195
196 /*******************************************************************************
197 *
198 * FUNCTION: TrAmlSetSubtreeParent
199 *
200 * PARAMETERS: Op - First node in a list of peer nodes
201 * Parent - Parent of the subtree
202 *
203 * RETURN: None
204 *
205 * DESCRIPTION: Set the parent for all peer nodes in a subtree
206 *
207 ******************************************************************************/
208
209 static void
210 TrAmlSetSubtreeParent (
211 ACPI_PARSE_OBJECT *Op,
212 ACPI_PARSE_OBJECT *Parent)
213 {
214 ACPI_PARSE_OBJECT *Next;
215
216
217 Next = Op;
218 while (Next)
219 {
220 Next->Asl.Parent = Parent;
221 Next = Next->Asl.Next;
222 }
223 }
224
225
226 /*******************************************************************************
227 *
228 * FUNCTION: TrAmlInsertPeer
229 *
230 * PARAMETERS: Op - First node in a list of peer nodes
231 * NewPeer - Peer node to insert
232 *
233 * RETURN: None
234 *
235 * DESCRIPTION: Insert a new peer node into a list of peers.
236 *
237 ******************************************************************************/
238
239 static void
240 TrAmlInsertPeer (
241 ACPI_PARSE_OBJECT *Op,
242 ACPI_PARSE_OBJECT *NewPeer)
243 {
244
245 NewPeer->Asl.Next = Op->Asl.Next;
246 Op->Asl.Next = NewPeer;
247 }
248
249
250 /*******************************************************************************
251 *
252 * FUNCTION: TrAmlTransformWalkBegin
253 *
254 * PARAMETERS: ASL_WALK_CALLBACK
255 *
256 * RETURN: None
257 *
258 * DESCRIPTION: Parse tree walk to generate both the AML opcodes and the AML
259 * operands.
260 *
261 ******************************************************************************/
262
263 ACPI_STATUS
264 TrAmlTransformWalkBegin (
265 ACPI_PARSE_OBJECT *Op,
266 UINT32 Level,
267 void *Context)
268 {
269
270 TrTransformSubtree (Op);
271 return (AE_OK);
272 }
273
274
275 /*******************************************************************************
276 *
277 * FUNCTION: TrAmlTransformWalkEnd
278 *
279 * PARAMETERS: ASL_WALK_CALLBACK
280 *
281 * RETURN: None
282 *
283 * DESCRIPTION: Parse tree walk to generate both the AML opcodes and the AML
284 * operands.
285 *
286 ******************************************************************************/
287
288 ACPI_STATUS
289 TrAmlTransformWalkEnd (
290 ACPI_PARSE_OBJECT *Op,
291 UINT32 Level,
292 void *Context)
293 {
294
295 /* Save possible Externals list in the DefintionBlock Op */
296
297 if (Op->Asl.ParseOpcode == PARSEOP_DEFINITION_BLOCK)
298 {
299 Op->Asl.Value.Arg = Gbl_ExternalsListHead;
300 Gbl_ExternalsListHead = NULL;
301 }
302
303 return (AE_OK);
304 }
305
306
307 /*******************************************************************************
308 *
309 * FUNCTION: TrTransformSubtree
310 *
311 * PARAMETERS: Op - The parent parse node
312 *
313 * RETURN: None
314 *
315 * DESCRIPTION: Prepare nodes to be output as AML data and operands. The more
316 * complex AML opcodes require processing of the child nodes
317 * (arguments/operands).
318 *
319 ******************************************************************************/
320
321 static void
322 TrTransformSubtree (
323 ACPI_PARSE_OBJECT *Op)
324 {
325 ACPI_PARSE_OBJECT *MethodOp;
326
327
328 if (Op->Asl.AmlOpcode == AML_RAW_DATA_BYTE)
329 {
330 return;
331 }
332
333 switch (Op->Asl.ParseOpcode)
334 {
335 case PARSEOP_DEFINITION_BLOCK:
336
337 TrDoDefinitionBlock (Op);
338 break;
339
340 case PARSEOP_SWITCH:
341
342 TrDoSwitch (Op);
343 break;
344
345 case PARSEOP_METHOD:
346 /*
347 * TBD: Zero the tempname (_T_x) count. Probably shouldn't be a global,
348 * however
349 */
350 Gbl_TempCount = 0;
351 break;
352
353 case PARSEOP_EXTERNAL:
354
355 if (Gbl_DoExternals == TRUE)
356 {
357 ExDoExternal (Op);
358 }
359
360 break;
361
362 case PARSEOP___METHOD__:
363
364 /* Transform to a string op containing the parent method name */
365
366 Op->Asl.ParseOpcode = PARSEOP_STRING_LITERAL;
367 UtSetParseOpName (Op);
368
369 /* Find the parent control method op */
370
371 MethodOp = Op;
372 while (MethodOp)
373 {
374 if (MethodOp->Asl.ParseOpcode == PARSEOP_METHOD)
375 {
376 /* First child contains the method name */
377
378 MethodOp = MethodOp->Asl.Child;
379 Op->Asl.Value.String = MethodOp->Asl.Value.String;
380 return;
381 }
382
383 MethodOp = MethodOp->Asl.Parent;
384 }
385
386 /* At the root, invocation not within a control method */
387
388 Op->Asl.Value.String = "\\";
389 break;
390
391 case PARSEOP_UNLOAD:
392
393 AslError (ASL_WARNING, ASL_MSG_UNLOAD, Op, NULL);
394 break;
395
396 default:
397
398 /* Nothing to do here for other opcodes */
399
400 break;
401 }
402 }
403
404
405 /*******************************************************************************
406 *
407 * FUNCTION: TrDoDefinitionBlock
408 *
409 * PARAMETERS: Op - Parse node
410 *
411 * RETURN: None
412 *
413 * DESCRIPTION: Find the end of the definition block and set a global to this
414 * node. It is used by the compiler to insert compiler-generated
415 * names at the root level of the namespace.
416 *
417 ******************************************************************************/
418
419 static void
420 TrDoDefinitionBlock (
421 ACPI_PARSE_OBJECT *Op)
422 {
423 ACPI_PARSE_OBJECT *Next;
424 UINT32 i;
425
426
427 /* Reset external list when starting a definition block */
428
429 Gbl_ExternalsListHead = NULL;
430
431 Next = Op->Asl.Child;
432 for (i = 0; i < 5; i++)
433 {
434 Next = Next->Asl.Next;
435 if (i == 0)
436 {
437 /*
438 * This is the table signature. Only the DSDT can be assumed
439 * to be at the root of the namespace; Therefore, namepath
440 * optimization can only be performed on the DSDT.
441 */
442 if (!ACPI_COMPARE_NAME (Next->Asl.Value.String, ACPI_SIG_DSDT))
443 {
444 Gbl_ReferenceOptimizationFlag = FALSE;
445 }
446 }
447 }
448
449 Gbl_FirstLevelInsertionNode = Next;
450 }
451
452
453 /*******************************************************************************
454 *
455 * FUNCTION: TrDoSwitch
456 *
457 * PARAMETERS: StartNode - Parse node for SWITCH
458 *
459 * RETURN: None
460 *
461 * DESCRIPTION: Translate ASL SWITCH statement to if/else pairs. There is
462 * no actual AML opcode for SWITCH -- it must be simulated.
463 *
464 ******************************************************************************/
465
466 static void
467 TrDoSwitch (
468 ACPI_PARSE_OBJECT *StartNode)
469 {
470 ACPI_PARSE_OBJECT *Next;
471 ACPI_PARSE_OBJECT *CaseOp = NULL;
472 ACPI_PARSE_OBJECT *CaseBlock = NULL;
473 ACPI_PARSE_OBJECT *DefaultOp = NULL;
474 ACPI_PARSE_OBJECT *CurrentParentNode;
475 ACPI_PARSE_OBJECT *Conditional = NULL;
476 ACPI_PARSE_OBJECT *Predicate;
477 ACPI_PARSE_OBJECT *Peer;
478 ACPI_PARSE_OBJECT *NewOp;
479 ACPI_PARSE_OBJECT *NewOp2;
480 ACPI_PARSE_OBJECT *MethodOp;
481 ACPI_PARSE_OBJECT *StoreOp;
482 ACPI_PARSE_OBJECT *BreakOp;
483 ACPI_PARSE_OBJECT *BufferOp;
484 char *PredicateValueName;
485 UINT16 Index;
486 UINT32 Btype;
487
488
489 /* Start node is the Switch() node */
490
491 CurrentParentNode = StartNode;
492
493 /* Create a new temp name of the form _T_x */
494
495 PredicateValueName = TrAmlGetNextTempName (StartNode, &Gbl_TempCount);
496 if (!PredicateValueName)
497 {
498 return;
499 }
500
501 /* First child is the Switch() predicate */
502
503 Next = StartNode->Asl.Child;
504
505 /*
506 * Examine the return type of the Switch Value -
507 * must be Integer/Buffer/String
508 */
509 Index = (UINT16) (Next->Asl.ParseOpcode - ASL_PARSE_OPCODE_BASE);
510 Btype = AslKeywordMapping[Index].AcpiBtype;
511 if ((Btype != ACPI_BTYPE_INTEGER) &&
512 (Btype != ACPI_BTYPE_STRING) &&
513 (Btype != ACPI_BTYPE_BUFFER))
514 {
515 AslError (ASL_WARNING, ASL_MSG_SWITCH_TYPE, Next, NULL);
516 Btype = ACPI_BTYPE_INTEGER;
517 }
518
519 /* CASE statements start at next child */
520
521 Peer = Next->Asl.Next;
522 while (Peer)
523 {
524 Next = Peer;
525 Peer = Next->Asl.Next;
526
527 if (Next->Asl.ParseOpcode == PARSEOP_CASE)
528 {
529 if (CaseOp)
530 {
531 /* Add an ELSE to complete the previous CASE */
532
533 NewOp = TrCreateLeafOp (PARSEOP_ELSE);
534 NewOp->Asl.Parent = Conditional->Asl.Parent;
535 TrAmlInitLineNumbers (NewOp, NewOp->Asl.Parent);
536
537 /* Link ELSE node as a peer to the previous IF */
538
539 TrAmlInsertPeer (Conditional, NewOp);
540 CurrentParentNode = NewOp;
541 }
542
543 CaseOp = Next;
544 Conditional = CaseOp;
545 CaseBlock = CaseOp->Asl.Child->Asl.Next;
546 Conditional->Asl.Child->Asl.Next = NULL;
547 Predicate = CaseOp->Asl.Child;
548
549 if ((Predicate->Asl.ParseOpcode == PARSEOP_PACKAGE) ||
550 (Predicate->Asl.ParseOpcode == PARSEOP_VAR_PACKAGE))
551 {
552 /*
553 * Convert the package declaration to this form:
554 *
555 * If (LNotEqual (Match (Package(<size>){<data>},
556 * MEQ, _T_x, MTR, Zero, Zero), Ones))
557 */
558 NewOp2 = TrCreateLeafOp (PARSEOP_MATCHTYPE_MEQ);
559 Predicate->Asl.Next = NewOp2;
560 TrAmlInitLineNumbers (NewOp2, Conditional);
561
562 NewOp = NewOp2;
563 NewOp2 = TrCreateValuedLeafOp (PARSEOP_NAMESTRING,
564 (UINT64) ACPI_TO_INTEGER (PredicateValueName));
565 NewOp->Asl.Next = NewOp2;
566 TrAmlInitLineNumbers (NewOp2, Predicate);
567
568 NewOp = NewOp2;
569 NewOp2 = TrCreateLeafOp (PARSEOP_MATCHTYPE_MTR);
570 NewOp->Asl.Next = NewOp2;
571 TrAmlInitLineNumbers (NewOp2, Predicate);
572
573 NewOp = NewOp2;
574 NewOp2 = TrCreateLeafOp (PARSEOP_ZERO);
575 NewOp->Asl.Next = NewOp2;
576 TrAmlInitLineNumbers (NewOp2, Predicate);
577
578 NewOp = NewOp2;
579 NewOp2 = TrCreateLeafOp (PARSEOP_ZERO);
580 NewOp->Asl.Next = NewOp2;
581 TrAmlInitLineNumbers (NewOp2, Predicate);
582
583 NewOp2 = TrCreateLeafOp (PARSEOP_MATCH);
584 NewOp2->Asl.Child = Predicate; /* PARSEOP_PACKAGE */
585 TrAmlInitLineNumbers (NewOp2, Conditional);
586 TrAmlSetSubtreeParent (Predicate, NewOp2);
587
588 NewOp = NewOp2;
589 NewOp2 = TrCreateLeafOp (PARSEOP_ONES);
590 NewOp->Asl.Next = NewOp2;
591 TrAmlInitLineNumbers (NewOp2, Conditional);
592
593 NewOp2 = TrCreateLeafOp (PARSEOP_LEQUAL);
594 NewOp2->Asl.Child = NewOp;
595 NewOp->Asl.Parent = NewOp2;
596 TrAmlInitLineNumbers (NewOp2, Conditional);
597 TrAmlSetSubtreeParent (NewOp, NewOp2);
598
599 NewOp = NewOp2;
600 NewOp2 = TrCreateLeafOp (PARSEOP_LNOT);
601 NewOp2->Asl.Child = NewOp;
602 NewOp2->Asl.Parent = Conditional;
603 NewOp->Asl.Parent = NewOp2;
604 TrAmlInitLineNumbers (NewOp2, Conditional);
605
606 Conditional->Asl.Child = NewOp2;
607 NewOp2->Asl.Next = CaseBlock;
608 }
609 else
610 {
611 /*
612 * Integer and Buffer case.
613 *
614 * Change CaseOp() to: If (LEqual (SwitchValue, CaseValue)) {...}
615 * Note: SwitchValue is first to allow the CaseValue to be implicitly
616 * converted to the type of SwitchValue if necessary.
617 *
618 * CaseOp->Child is the case value
619 * CaseOp->Child->Peer is the beginning of the case block
620 */
621 NewOp = TrCreateValuedLeafOp (PARSEOP_NAMESTRING,
622 (UINT64) ACPI_TO_INTEGER (PredicateValueName));
623 NewOp->Asl.Next = Predicate;
624 TrAmlInitLineNumbers (NewOp, Predicate);
625
626 NewOp2 = TrCreateLeafOp (PARSEOP_LEQUAL);
627 NewOp2->Asl.Parent = Conditional;
628 NewOp2->Asl.Child = NewOp;
629 TrAmlInitLineNumbers (NewOp2, Conditional);
630
631 TrAmlSetSubtreeParent (NewOp, NewOp2);
632
633 Predicate = NewOp2;
634 Predicate->Asl.Next = CaseBlock;
635
636 TrAmlSetSubtreeParent (Predicate, Conditional);
637 Conditional->Asl.Child = Predicate;
638 }
639
640 /* Reinitialize the CASE node to an IF node */
641
642 TrAmlInitNode (Conditional, PARSEOP_IF);
643
644 /*
645 * The first CASE(IF) is not nested under an ELSE.
646 * All other CASEs are children of a parent ELSE.
647 */
648 if (CurrentParentNode == StartNode)
649 {
650 Conditional->Asl.Next = NULL;
651 }
652 else
653 {
654 /*
655 * The IF is a child of previous IF/ELSE. It
656 * is therefore without peer.
657 */
658 CurrentParentNode->Asl.Child = Conditional;
659 Conditional->Asl.Parent = CurrentParentNode;
660 Conditional->Asl.Next = NULL;
661 }
662 }
663 else if (Next->Asl.ParseOpcode == PARSEOP_DEFAULT)
664 {
665 if (DefaultOp)
666 {
667 /*
668 * More than one Default
669 * (Parser does not catch this, must check here)
670 */
671 AslError (ASL_ERROR, ASL_MSG_MULTIPLE_DEFAULT, Next, NULL);
672 }
673 else
674 {
675 /* Save the DEFAULT node for later, after CASEs */
676
677 DefaultOp = Next;
678 }
679 }
680 else
681 {
682 /* Unknown peer opcode */
683
684 AcpiOsPrintf ("Unknown parse opcode for switch statement: %s (%u)\n",
685 Next->Asl.ParseOpName, Next->Asl.ParseOpcode);
686 }
687 }
688
689 /* Add the default case at the end of the if/else construct */
690
691 if (DefaultOp)
692 {
693 /* If no CASE statements, this is an error - see below */
694
695 if (CaseOp)
696 {
697 /* Convert the DEFAULT node to an ELSE */
698
699 TrAmlInitNode (DefaultOp, PARSEOP_ELSE);
700 DefaultOp->Asl.Parent = Conditional->Asl.Parent;
701
702 /* Link ELSE node as a peer to the previous IF */
703
704 TrAmlInsertPeer (Conditional, DefaultOp);
705 }
706 }
707
708 if (!CaseOp)
709 {
710 AslError (ASL_ERROR, ASL_MSG_NO_CASES, StartNode, NULL);
711 }
712
713
714 /*
715 * Create a Name(_T_x, ...) statement. This statement must appear at the
716 * method level, in case a loop surrounds the switch statement and could
717 * cause the name to be created twice (error).
718 */
719
720 /* Create the Name node */
721
722 Predicate = StartNode->Asl.Child;
723 NewOp = TrCreateLeafOp (PARSEOP_NAME);
724 TrAmlInitLineNumbers (NewOp, StartNode);
725
726 /* Find the parent method */
727
728 Next = StartNode;
729 while ((Next->Asl.ParseOpcode != PARSEOP_METHOD) &&
730 (Next->Asl.ParseOpcode != PARSEOP_DEFINITION_BLOCK))
731 {
732 Next = Next->Asl.Parent;
733 }
734 MethodOp = Next;
735
736 NewOp->Asl.CompileFlags |= OP_COMPILER_EMITTED;
737 NewOp->Asl.Parent = Next;
738
739 /* Insert name after the method name and arguments */
740
741 Next = Next->Asl.Child; /* Name */
742 Next = Next->Asl.Next; /* NumArgs */
743 Next = Next->Asl.Next; /* SerializeRule */
744
745 /*
746 * If method is not Serialized, we must make is so, because of the way
747 * that Switch() must be implemented -- we cannot allow multiple threads
748 * to execute this method concurrently since we need to create local
749 * temporary name(s).
750 */
751 if (Next->Asl.ParseOpcode != PARSEOP_SERIALIZERULE_SERIAL)
752 {
753 AslError (ASL_REMARK, ASL_MSG_SERIALIZED, MethodOp,
754 "Due to use of Switch operator");
755 Next->Asl.ParseOpcode = PARSEOP_SERIALIZERULE_SERIAL;
756 }
757
758 Next = Next->Asl.Next; /* SyncLevel */
759 Next = Next->Asl.Next; /* ReturnType */
760 Next = Next->Asl.Next; /* ParameterTypes */
761
762 TrAmlInsertPeer (Next, NewOp);
763 TrAmlInitLineNumbers (NewOp, Next);
764
765 /* Create the NameSeg child for the Name node */
766
767 NewOp2 = TrCreateValuedLeafOp (PARSEOP_NAMESEG,
768 (UINT64) ACPI_TO_INTEGER (PredicateValueName));
769 TrAmlInitLineNumbers (NewOp2, NewOp);
770 NewOp2->Asl.CompileFlags |= OP_IS_NAME_DECLARATION;
771 NewOp->Asl.Child = NewOp2;
772
773 /* Create the initial value for the Name. Btype was already validated above */
774
775 switch (Btype)
776 {
777 case ACPI_BTYPE_INTEGER:
778
779 NewOp2->Asl.Next = TrCreateValuedLeafOp (PARSEOP_ZERO,
780 (UINT64) 0);
781 TrAmlInitLineNumbers (NewOp2->Asl.Next, NewOp);
782 break;
783
784 case ACPI_BTYPE_STRING:
785
786 NewOp2->Asl.Next = TrCreateValuedLeafOp (PARSEOP_STRING_LITERAL,
787 (UINT64) ACPI_TO_INTEGER (""));
788 TrAmlInitLineNumbers (NewOp2->Asl.Next, NewOp);
789 break;
790
791 case ACPI_BTYPE_BUFFER:
792
793 (void) TrLinkPeerOp (NewOp2, TrCreateValuedLeafOp (PARSEOP_BUFFER,
794 (UINT64) 0));
795 Next = NewOp2->Asl.Next;
796 TrAmlInitLineNumbers (Next, NewOp2);
797
798 (void) TrLinkOpChildren (Next, 1, TrCreateValuedLeafOp (PARSEOP_ZERO,
799 (UINT64) 1));
800 TrAmlInitLineNumbers (Next->Asl.Child, Next);
801
802 BufferOp = TrCreateValuedLeafOp (PARSEOP_DEFAULT_ARG, (UINT64) 0);
803 TrAmlInitLineNumbers (BufferOp, Next->Asl.Child);
804 (void) TrLinkPeerOp (Next->Asl.Child, BufferOp);
805
806 TrAmlSetSubtreeParent (Next->Asl.Child, Next);
807 break;
808
809 default:
810
811 break;
812 }
813
814 TrAmlSetSubtreeParent (NewOp2, NewOp);
815
816 /*
817 * Transform the Switch() into a While(One)-Break node.
818 * And create a Store() node which will be used to save the
819 * Switch() value. The store is of the form: Store (Value, _T_x)
820 * where _T_x is the temp variable.
821 */
822 TrAmlInitNode (StartNode, PARSEOP_WHILE);
823 NewOp = TrCreateLeafOp (PARSEOP_ONE);
824 TrAmlInitLineNumbers (NewOp, StartNode);
825 NewOp->Asl.Next = Predicate->Asl.Next;
826 NewOp->Asl.Parent = StartNode;
827 StartNode->Asl.Child = NewOp;
828
829 /* Create a Store() node */
830
831 StoreOp = TrCreateLeafOp (PARSEOP_STORE);
832 TrAmlInitLineNumbers (StoreOp, NewOp);
833 StoreOp->Asl.Parent = StartNode;
834 TrAmlInsertPeer (NewOp, StoreOp);
835
836 /* Complete the Store subtree */
837
838 StoreOp->Asl.Child = Predicate;
839 Predicate->Asl.Parent = StoreOp;
840
841 NewOp = TrCreateValuedLeafOp (PARSEOP_NAMESEG,
842 (UINT64) ACPI_TO_INTEGER (PredicateValueName));
843 TrAmlInitLineNumbers (NewOp, StoreOp);
844 NewOp->Asl.Parent = StoreOp;
845 Predicate->Asl.Next = NewOp;
846
847 /* Create a Break() node and insert it into the end of While() */
848
849 Conditional = StartNode->Asl.Child;
850 while (Conditional->Asl.Next)
851 {
852 Conditional = Conditional->Asl.Next;
853 }
854
855 BreakOp = TrCreateLeafOp (PARSEOP_BREAK);
856 TrAmlInitLineNumbers (BreakOp, NewOp);
857 BreakOp->Asl.Parent = StartNode;
858 TrAmlInsertPeer (Conditional, BreakOp);
859 }
860