xref: /freebsd/sys/contrib/dev/acpica/compiler/cvdisasm.c (revision 0d84335f991f528c6f038e79dd5cc0a7770532da)
1*0d84335fSJung-uk Kim /******************************************************************************
2*0d84335fSJung-uk Kim  *
3*0d84335fSJung-uk Kim  * Module Name: cvcompiler - ASL-/ASL+ converter functions
4*0d84335fSJung-uk Kim  *
5*0d84335fSJung-uk Kim  *****************************************************************************/
6*0d84335fSJung-uk Kim 
7*0d84335fSJung-uk Kim /******************************************************************************
8*0d84335fSJung-uk Kim  *
9*0d84335fSJung-uk Kim  * 1. Copyright Notice
10*0d84335fSJung-uk Kim  *
11*0d84335fSJung-uk Kim  * Some or all of this work - Copyright (c) 1999 - 2017, Intel Corp.
12*0d84335fSJung-uk Kim  * All rights reserved.
13*0d84335fSJung-uk Kim  *
14*0d84335fSJung-uk Kim  * 2. License
15*0d84335fSJung-uk Kim  *
16*0d84335fSJung-uk Kim  * 2.1. This is your license from Intel Corp. under its intellectual property
17*0d84335fSJung-uk Kim  * rights. You may have additional license terms from the party that provided
18*0d84335fSJung-uk Kim  * you this software, covering your right to use that party's intellectual
19*0d84335fSJung-uk Kim  * property rights.
20*0d84335fSJung-uk Kim  *
21*0d84335fSJung-uk Kim  * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
22*0d84335fSJung-uk Kim  * copy of the source code appearing in this file ("Covered Code") an
23*0d84335fSJung-uk Kim  * irrevocable, perpetual, worldwide license under Intel's copyrights in the
24*0d84335fSJung-uk Kim  * base code distributed originally by Intel ("Original Intel Code") to copy,
25*0d84335fSJung-uk Kim  * make derivatives, distribute, use and display any portion of the Covered
26*0d84335fSJung-uk Kim  * Code in any form, with the right to sublicense such rights; and
27*0d84335fSJung-uk Kim  *
28*0d84335fSJung-uk Kim  * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
29*0d84335fSJung-uk Kim  * license (with the right to sublicense), under only those claims of Intel
30*0d84335fSJung-uk Kim  * patents that are infringed by the Original Intel Code, to make, use, sell,
31*0d84335fSJung-uk Kim  * offer to sell, and import the Covered Code and derivative works thereof
32*0d84335fSJung-uk Kim  * solely to the minimum extent necessary to exercise the above copyright
33*0d84335fSJung-uk Kim  * license, and in no event shall the patent license extend to any additions
34*0d84335fSJung-uk Kim  * to or modifications of the Original Intel Code. No other license or right
35*0d84335fSJung-uk Kim  * is granted directly or by implication, estoppel or otherwise;
36*0d84335fSJung-uk Kim  *
37*0d84335fSJung-uk Kim  * The above copyright and patent license is granted only if the following
38*0d84335fSJung-uk Kim  * conditions are met:
39*0d84335fSJung-uk Kim  *
40*0d84335fSJung-uk Kim  * 3. Conditions
41*0d84335fSJung-uk Kim  *
42*0d84335fSJung-uk Kim  * 3.1. Redistribution of Source with Rights to Further Distribute Source.
43*0d84335fSJung-uk Kim  * Redistribution of source code of any substantial portion of the Covered
44*0d84335fSJung-uk Kim  * Code or modification with rights to further distribute source must include
45*0d84335fSJung-uk Kim  * the above Copyright Notice, the above License, this list of Conditions,
46*0d84335fSJung-uk Kim  * and the following Disclaimer and Export Compliance provision. In addition,
47*0d84335fSJung-uk Kim  * Licensee must cause all Covered Code to which Licensee contributes to
48*0d84335fSJung-uk Kim  * contain a file documenting the changes Licensee made to create that Covered
49*0d84335fSJung-uk Kim  * Code and the date of any change. Licensee must include in that file the
50*0d84335fSJung-uk Kim  * documentation of any changes made by any predecessor Licensee. Licensee
51*0d84335fSJung-uk Kim  * must include a prominent statement that the modification is derived,
52*0d84335fSJung-uk Kim  * directly or indirectly, from Original Intel Code.
53*0d84335fSJung-uk Kim  *
54*0d84335fSJung-uk Kim  * 3.2. Redistribution of Source with no Rights to Further Distribute Source.
55*0d84335fSJung-uk Kim  * Redistribution of source code of any substantial portion of the Covered
56*0d84335fSJung-uk Kim  * Code or modification without rights to further distribute source must
57*0d84335fSJung-uk Kim  * include the following Disclaimer and Export Compliance provision in the
58*0d84335fSJung-uk Kim  * documentation and/or other materials provided with distribution. In
59*0d84335fSJung-uk Kim  * addition, Licensee may not authorize further sublicense of source of any
60*0d84335fSJung-uk Kim  * portion of the Covered Code, and must include terms to the effect that the
61*0d84335fSJung-uk Kim  * license from Licensee to its licensee is limited to the intellectual
62*0d84335fSJung-uk Kim  * property embodied in the software Licensee provides to its licensee, and
63*0d84335fSJung-uk Kim  * not to intellectual property embodied in modifications its licensee may
64*0d84335fSJung-uk Kim  * make.
65*0d84335fSJung-uk Kim  *
66*0d84335fSJung-uk Kim  * 3.3. Redistribution of Executable. Redistribution in executable form of any
67*0d84335fSJung-uk Kim  * substantial portion of the Covered Code or modification must reproduce the
68*0d84335fSJung-uk Kim  * above Copyright Notice, and the following Disclaimer and Export Compliance
69*0d84335fSJung-uk Kim  * provision in the documentation and/or other materials provided with the
70*0d84335fSJung-uk Kim  * distribution.
71*0d84335fSJung-uk Kim  *
72*0d84335fSJung-uk Kim  * 3.4. Intel retains all right, title, and interest in and to the Original
73*0d84335fSJung-uk Kim  * Intel Code.
74*0d84335fSJung-uk Kim  *
75*0d84335fSJung-uk Kim  * 3.5. Neither the name Intel nor any other trademark owned or controlled by
76*0d84335fSJung-uk Kim  * Intel shall be used in advertising or otherwise to promote the sale, use or
77*0d84335fSJung-uk Kim  * other dealings in products derived from or relating to the Covered Code
78*0d84335fSJung-uk Kim  * without prior written authorization from Intel.
79*0d84335fSJung-uk Kim  *
80*0d84335fSJung-uk Kim  * 4. Disclaimer and Export Compliance
81*0d84335fSJung-uk Kim  *
82*0d84335fSJung-uk Kim  * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
83*0d84335fSJung-uk Kim  * HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
84*0d84335fSJung-uk Kim  * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE,
85*0d84335fSJung-uk Kim  * INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY
86*0d84335fSJung-uk Kim  * UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY
87*0d84335fSJung-uk Kim  * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
88*0d84335fSJung-uk Kim  * PARTICULAR PURPOSE.
89*0d84335fSJung-uk Kim  *
90*0d84335fSJung-uk Kim  * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
91*0d84335fSJung-uk Kim  * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
92*0d84335fSJung-uk Kim  * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
93*0d84335fSJung-uk Kim  * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
94*0d84335fSJung-uk Kim  * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
95*0d84335fSJung-uk Kim  * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS
96*0d84335fSJung-uk Kim  * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
97*0d84335fSJung-uk Kim  * LIMITED REMEDY.
98*0d84335fSJung-uk Kim  *
99*0d84335fSJung-uk Kim  * 4.3. Licensee shall not export, either directly or indirectly, any of this
100*0d84335fSJung-uk Kim  * software or system incorporating such software without first obtaining any
101*0d84335fSJung-uk Kim  * required license or other approval from the U. S. Department of Commerce or
102*0d84335fSJung-uk Kim  * any other agency or department of the United States Government. In the
103*0d84335fSJung-uk Kim  * event Licensee exports any such software from the United States or
104*0d84335fSJung-uk Kim  * re-exports any such software from a foreign destination, Licensee shall
105*0d84335fSJung-uk Kim  * ensure that the distribution and export/re-export of the software is in
106*0d84335fSJung-uk Kim  * compliance with all laws, regulations, orders, or other restrictions of the
107*0d84335fSJung-uk Kim  * U.S. Export Administration Regulations. Licensee agrees that neither it nor
108*0d84335fSJung-uk Kim  * any of its subsidiaries will export/re-export any technical data, process,
109*0d84335fSJung-uk Kim  * software, or service, directly or indirectly, to any country for which the
110*0d84335fSJung-uk Kim  * United States government or any agency thereof requires an export license,
111*0d84335fSJung-uk Kim  * other governmental approval, or letter of assurance, without first obtaining
112*0d84335fSJung-uk Kim  * such license, approval or letter.
113*0d84335fSJung-uk Kim  *
114*0d84335fSJung-uk Kim  *****************************************************************************
115*0d84335fSJung-uk Kim  *
116*0d84335fSJung-uk Kim  * Alternatively, you may choose to be licensed under the terms of the
117*0d84335fSJung-uk Kim  * following license:
118*0d84335fSJung-uk Kim  *
119*0d84335fSJung-uk Kim  * Redistribution and use in source and binary forms, with or without
120*0d84335fSJung-uk Kim  * modification, are permitted provided that the following conditions
121*0d84335fSJung-uk Kim  * are met:
122*0d84335fSJung-uk Kim  * 1. Redistributions of source code must retain the above copyright
123*0d84335fSJung-uk Kim  *    notice, this list of conditions, and the following disclaimer,
124*0d84335fSJung-uk Kim  *    without modification.
125*0d84335fSJung-uk Kim  * 2. Redistributions in binary form must reproduce at minimum a disclaimer
126*0d84335fSJung-uk Kim  *    substantially similar to the "NO WARRANTY" disclaimer below
127*0d84335fSJung-uk Kim  *    ("Disclaimer") and any redistribution must be conditioned upon
128*0d84335fSJung-uk Kim  *    including a substantially similar Disclaimer requirement for further
129*0d84335fSJung-uk Kim  *    binary redistribution.
130*0d84335fSJung-uk Kim  * 3. Neither the names of the above-listed copyright holders nor the names
131*0d84335fSJung-uk Kim  *    of any contributors may be used to endorse or promote products derived
132*0d84335fSJung-uk Kim  *    from this software without specific prior written permission.
133*0d84335fSJung-uk Kim  *
134*0d84335fSJung-uk Kim  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
135*0d84335fSJung-uk Kim  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
136*0d84335fSJung-uk Kim  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
137*0d84335fSJung-uk Kim  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
138*0d84335fSJung-uk Kim  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
139*0d84335fSJung-uk Kim  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
140*0d84335fSJung-uk Kim  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
141*0d84335fSJung-uk Kim  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
142*0d84335fSJung-uk Kim  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
143*0d84335fSJung-uk Kim  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
144*0d84335fSJung-uk Kim  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
145*0d84335fSJung-uk Kim  *
146*0d84335fSJung-uk Kim  * Alternatively, you may choose to be licensed under the terms of the
147*0d84335fSJung-uk Kim  * GNU General Public License ("GPL") version 2 as published by the Free
148*0d84335fSJung-uk Kim  * Software Foundation.
149*0d84335fSJung-uk Kim  *
150*0d84335fSJung-uk Kim  *****************************************************************************/
151*0d84335fSJung-uk Kim 
152*0d84335fSJung-uk Kim #include <contrib/dev/acpica/compiler/aslcompiler.h>
153*0d84335fSJung-uk Kim #include <contrib/dev/acpica/include/acparser.h>
154*0d84335fSJung-uk Kim #include <contrib/dev/acpica/include/amlcode.h>
155*0d84335fSJung-uk Kim #include <contrib/dev/acpica/include/acdebug.h>
156*0d84335fSJung-uk Kim #include <contrib/dev/acpica/include/acconvert.h>
157*0d84335fSJung-uk Kim 
158*0d84335fSJung-uk Kim 
159*0d84335fSJung-uk Kim static void
160*0d84335fSJung-uk Kim CvPrintInclude(
161*0d84335fSJung-uk Kim     ACPI_FILE_NODE          *FNode,
162*0d84335fSJung-uk Kim     UINT32                  Level);
163*0d84335fSJung-uk Kim 
164*0d84335fSJung-uk Kim static BOOLEAN
165*0d84335fSJung-uk Kim CvListIsSingleton (
166*0d84335fSJung-uk Kim     ACPI_COMMENT_NODE       *CommentList);
167*0d84335fSJung-uk Kim 
168*0d84335fSJung-uk Kim 
169*0d84335fSJung-uk Kim /*******************************************************************************
170*0d84335fSJung-uk Kim  *
171*0d84335fSJung-uk Kim  * FUNCTION:    CvPrintOneCommentList
172*0d84335fSJung-uk Kim  *
173*0d84335fSJung-uk Kim  * PARAMETERS:  CommentList
174*0d84335fSJung-uk Kim  *              Level
175*0d84335fSJung-uk Kim  *
176*0d84335fSJung-uk Kim  * RETURN:      None
177*0d84335fSJung-uk Kim  *
178*0d84335fSJung-uk Kim  * DESCRIPTION: Prints all comments within the given list.
179*0d84335fSJung-uk Kim  *              This is referred as ASL_CV_PRINT_ONE_COMMENT_LIST.
180*0d84335fSJung-uk Kim  *
181*0d84335fSJung-uk Kim  ******************************************************************************/
182*0d84335fSJung-uk Kim 
183*0d84335fSJung-uk Kim void
184*0d84335fSJung-uk Kim CvPrintOneCommentList (
185*0d84335fSJung-uk Kim     ACPI_COMMENT_NODE       *CommentList,
186*0d84335fSJung-uk Kim     UINT32                  Level)
187*0d84335fSJung-uk Kim {
188*0d84335fSJung-uk Kim     ACPI_COMMENT_NODE       *Current = CommentList;
189*0d84335fSJung-uk Kim     ACPI_COMMENT_NODE       *Previous;
190*0d84335fSJung-uk Kim 
191*0d84335fSJung-uk Kim 
192*0d84335fSJung-uk Kim     while (Current)
193*0d84335fSJung-uk Kim     {
194*0d84335fSJung-uk Kim         Previous = Current;
195*0d84335fSJung-uk Kim         if (Current->Comment)
196*0d84335fSJung-uk Kim         {
197*0d84335fSJung-uk Kim             AcpiDmIndent(Level);
198*0d84335fSJung-uk Kim             AcpiOsPrintf("%s\n", Current->Comment);
199*0d84335fSJung-uk Kim             Current->Comment = NULL;
200*0d84335fSJung-uk Kim         }
201*0d84335fSJung-uk Kim         Current = Current->Next;
202*0d84335fSJung-uk Kim         AcpiOsReleaseObject(AcpiGbl_RegCommentCache, Previous);
203*0d84335fSJung-uk Kim     }
204*0d84335fSJung-uk Kim }
205*0d84335fSJung-uk Kim 
206*0d84335fSJung-uk Kim 
207*0d84335fSJung-uk Kim /*******************************************************************************
208*0d84335fSJung-uk Kim  *
209*0d84335fSJung-uk Kim  * FUNCTION:    CvListIsSingleton
210*0d84335fSJung-uk Kim  *
211*0d84335fSJung-uk Kim  * PARAMETERS:  CommentList -- check to see if this is a single item list.
212*0d84335fSJung-uk Kim  *
213*0d84335fSJung-uk Kim  * RETURN:      BOOLEAN
214*0d84335fSJung-uk Kim  *
215*0d84335fSJung-uk Kim  * DESCRIPTION: Returns TRUE if CommentList only contains 1 node.
216*0d84335fSJung-uk Kim  *
217*0d84335fSJung-uk Kim  ******************************************************************************/
218*0d84335fSJung-uk Kim 
219*0d84335fSJung-uk Kim static BOOLEAN
220*0d84335fSJung-uk Kim CvListIsSingleton (
221*0d84335fSJung-uk Kim     ACPI_COMMENT_NODE       *CommentList)
222*0d84335fSJung-uk Kim 
223*0d84335fSJung-uk Kim {
224*0d84335fSJung-uk Kim     if (!CommentList)
225*0d84335fSJung-uk Kim     {
226*0d84335fSJung-uk Kim         return FALSE;
227*0d84335fSJung-uk Kim     }
228*0d84335fSJung-uk Kim     else if (CommentList->Next)
229*0d84335fSJung-uk Kim     {
230*0d84335fSJung-uk Kim         return FALSE;
231*0d84335fSJung-uk Kim     }
232*0d84335fSJung-uk Kim 
233*0d84335fSJung-uk Kim     return TRUE;
234*0d84335fSJung-uk Kim }
235*0d84335fSJung-uk Kim 
236*0d84335fSJung-uk Kim 
237*0d84335fSJung-uk Kim /*******************************************************************************
238*0d84335fSJung-uk Kim  *
239*0d84335fSJung-uk Kim  * FUNCTION:    CvPrintOneCommentType
240*0d84335fSJung-uk Kim  *
241*0d84335fSJung-uk Kim  * PARAMETERS:  Op
242*0d84335fSJung-uk Kim  *              CommentType
243*0d84335fSJung-uk Kim  *              EndStr - String to print after printing the comment
244*0d84335fSJung-uk Kim  *              Level  - indentation level for comment lists.
245*0d84335fSJung-uk Kim  *
246*0d84335fSJung-uk Kim  * RETURN:      None
247*0d84335fSJung-uk Kim  *
248*0d84335fSJung-uk Kim  * DESCRIPTION: Prints all comments of CommentType within the given Op and
249*0d84335fSJung-uk Kim  *              clears the printed comment from the Op.
250*0d84335fSJung-uk Kim  *              This is referred as ASL_CV_PRINT_ONE_COMMENT.
251*0d84335fSJung-uk Kim  *
252*0d84335fSJung-uk Kim  ******************************************************************************/
253*0d84335fSJung-uk Kim 
254*0d84335fSJung-uk Kim void
255*0d84335fSJung-uk Kim CvPrintOneCommentType (
256*0d84335fSJung-uk Kim     ACPI_PARSE_OBJECT       *Op,
257*0d84335fSJung-uk Kim     UINT8                   CommentType,
258*0d84335fSJung-uk Kim     char*                   EndStr,
259*0d84335fSJung-uk Kim     UINT32                  Level)
260*0d84335fSJung-uk Kim {
261*0d84335fSJung-uk Kim     BOOLEAN                 CommentExists = FALSE;
262*0d84335fSJung-uk Kim     char                    **CommentToPrint = NULL;
263*0d84335fSJung-uk Kim 
264*0d84335fSJung-uk Kim 
265*0d84335fSJung-uk Kim     switch (CommentType)
266*0d84335fSJung-uk Kim     {
267*0d84335fSJung-uk Kim     case AML_COMMENT_STANDARD:
268*0d84335fSJung-uk Kim 
269*0d84335fSJung-uk Kim         if (CvListIsSingleton (Op->Common.CommentList))
270*0d84335fSJung-uk Kim         {
271*0d84335fSJung-uk Kim             CvPrintOneCommentList (Op->Common.CommentList, Level);
272*0d84335fSJung-uk Kim             AcpiOsPrintf ("\n");
273*0d84335fSJung-uk Kim         }
274*0d84335fSJung-uk Kim         else
275*0d84335fSJung-uk Kim         {
276*0d84335fSJung-uk Kim             CvPrintOneCommentList (Op->Common.CommentList, Level);
277*0d84335fSJung-uk Kim         }
278*0d84335fSJung-uk Kim         Op->Common.CommentList = NULL;
279*0d84335fSJung-uk Kim         return;
280*0d84335fSJung-uk Kim 
281*0d84335fSJung-uk Kim     case AML_COMMENT_ENDBLK:
282*0d84335fSJung-uk Kim 
283*0d84335fSJung-uk Kim         if (Op->Common.EndBlkComment)
284*0d84335fSJung-uk Kim         {
285*0d84335fSJung-uk Kim             CvPrintOneCommentList (Op->Common.EndBlkComment, Level);
286*0d84335fSJung-uk Kim             Op->Common.EndBlkComment = NULL;
287*0d84335fSJung-uk Kim             AcpiDmIndent(Level);
288*0d84335fSJung-uk Kim         }
289*0d84335fSJung-uk Kim         return;
290*0d84335fSJung-uk Kim 
291*0d84335fSJung-uk Kim     case AMLCOMMENT_INLINE:
292*0d84335fSJung-uk Kim 
293*0d84335fSJung-uk Kim         CommentToPrint = &Op->Common.InlineComment;
294*0d84335fSJung-uk Kim         break;
295*0d84335fSJung-uk Kim 
296*0d84335fSJung-uk Kim     case AML_COMMENT_END_NODE:
297*0d84335fSJung-uk Kim 
298*0d84335fSJung-uk Kim         CommentToPrint = &Op->Common.EndNodeComment;
299*0d84335fSJung-uk Kim         break;
300*0d84335fSJung-uk Kim 
301*0d84335fSJung-uk Kim     case AML_NAMECOMMENT:
302*0d84335fSJung-uk Kim 
303*0d84335fSJung-uk Kim         CommentToPrint = &Op->Common.NameComment;
304*0d84335fSJung-uk Kim         break;
305*0d84335fSJung-uk Kim 
306*0d84335fSJung-uk Kim     case AML_COMMENT_CLOSE_BRACE:
307*0d84335fSJung-uk Kim 
308*0d84335fSJung-uk Kim         CommentToPrint = &Op->Common.CloseBraceComment;
309*0d84335fSJung-uk Kim         break;
310*0d84335fSJung-uk Kim 
311*0d84335fSJung-uk Kim     default:
312*0d84335fSJung-uk Kim         return;
313*0d84335fSJung-uk Kim     }
314*0d84335fSJung-uk Kim 
315*0d84335fSJung-uk Kim     if (*CommentToPrint)
316*0d84335fSJung-uk Kim     {
317*0d84335fSJung-uk Kim         AcpiOsPrintf ("%s", *CommentToPrint);
318*0d84335fSJung-uk Kim         *CommentToPrint = NULL;
319*0d84335fSJung-uk Kim     }
320*0d84335fSJung-uk Kim 
321*0d84335fSJung-uk Kim     if (CommentExists && EndStr)
322*0d84335fSJung-uk Kim     {
323*0d84335fSJung-uk Kim         AcpiOsPrintf ("%s", EndStr);
324*0d84335fSJung-uk Kim     }
325*0d84335fSJung-uk Kim }
326*0d84335fSJung-uk Kim 
327*0d84335fSJung-uk Kim 
328*0d84335fSJung-uk Kim /*******************************************************************************
329*0d84335fSJung-uk Kim  *
330*0d84335fSJung-uk Kim  * FUNCTION:    CvCloseBraceWriteComment
331*0d84335fSJung-uk Kim  *
332*0d84335fSJung-uk Kim  * PARAMETERS:  Op
333*0d84335fSJung-uk Kim  *              Level
334*0d84335fSJung-uk Kim  *
335*0d84335fSJung-uk Kim  * RETURN:      none
336*0d84335fSJung-uk Kim  *
337*0d84335fSJung-uk Kim  * DESCRIPTION: Print a close brace } and any open brace comments associated
338*0d84335fSJung-uk Kim  *              with this parse object.
339*0d84335fSJung-uk Kim  *              This is referred as ASL_CV_CLOSE_BRACE.
340*0d84335fSJung-uk Kim  *
341*0d84335fSJung-uk Kim  ******************************************************************************/
342*0d84335fSJung-uk Kim 
343*0d84335fSJung-uk Kim void
344*0d84335fSJung-uk Kim CvCloseBraceWriteComment(
345*0d84335fSJung-uk Kim     ACPI_PARSE_OBJECT       *Op,
346*0d84335fSJung-uk Kim     UINT32                  Level)
347*0d84335fSJung-uk Kim {
348*0d84335fSJung-uk Kim     if (!Gbl_CaptureComments)
349*0d84335fSJung-uk Kim     {
350*0d84335fSJung-uk Kim         AcpiOsPrintf ("}");
351*0d84335fSJung-uk Kim         return;
352*0d84335fSJung-uk Kim     }
353*0d84335fSJung-uk Kim 
354*0d84335fSJung-uk Kim     CvPrintOneCommentType (Op, AML_COMMENT_ENDBLK, NULL, Level);
355*0d84335fSJung-uk Kim     AcpiOsPrintf ("}");
356*0d84335fSJung-uk Kim     CvPrintOneCommentType (Op, AML_COMMENT_CLOSE_BRACE, NULL, Level);
357*0d84335fSJung-uk Kim }
358*0d84335fSJung-uk Kim 
359*0d84335fSJung-uk Kim 
360*0d84335fSJung-uk Kim /*******************************************************************************
361*0d84335fSJung-uk Kim  *
362*0d84335fSJung-uk Kim  * FUNCTION:    CvCloseParenWriteComment
363*0d84335fSJung-uk Kim  *
364*0d84335fSJung-uk Kim  * PARAMETERS:  Op
365*0d84335fSJung-uk Kim  *              Level
366*0d84335fSJung-uk Kim  *
367*0d84335fSJung-uk Kim  * RETURN:      none
368*0d84335fSJung-uk Kim  *
369*0d84335fSJung-uk Kim  * DESCRIPTION: Print a closing paren ) and any end node comments associated
370*0d84335fSJung-uk Kim  *              with this parse object.
371*0d84335fSJung-uk Kim  *              This is referred as ASL_CV_CLOSE_PAREN.
372*0d84335fSJung-uk Kim  *
373*0d84335fSJung-uk Kim  ******************************************************************************/
374*0d84335fSJung-uk Kim 
375*0d84335fSJung-uk Kim void
376*0d84335fSJung-uk Kim CvCloseParenWriteComment(
377*0d84335fSJung-uk Kim     ACPI_PARSE_OBJECT       *Op,
378*0d84335fSJung-uk Kim     UINT32                  Level)
379*0d84335fSJung-uk Kim {
380*0d84335fSJung-uk Kim     if (!Gbl_CaptureComments)
381*0d84335fSJung-uk Kim     {
382*0d84335fSJung-uk Kim         AcpiOsPrintf (")");
383*0d84335fSJung-uk Kim         return;
384*0d84335fSJung-uk Kim     }
385*0d84335fSJung-uk Kim 
386*0d84335fSJung-uk Kim     /*
387*0d84335fSJung-uk Kim      * If this op has a BLOCK_BRACE, then output the comment when the
388*0d84335fSJung-uk Kim      * disassembler calls CvCloseBraceWriteComment
389*0d84335fSJung-uk Kim      */
390*0d84335fSJung-uk Kim     if (AcpiDmBlockType (Op) == BLOCK_PAREN)
391*0d84335fSJung-uk Kim     {
392*0d84335fSJung-uk Kim         CvPrintOneCommentType (Op, AML_COMMENT_ENDBLK, NULL, Level);
393*0d84335fSJung-uk Kim     }
394*0d84335fSJung-uk Kim 
395*0d84335fSJung-uk Kim     AcpiOsPrintf (")");
396*0d84335fSJung-uk Kim 
397*0d84335fSJung-uk Kim     if (Op->Common.EndNodeComment)
398*0d84335fSJung-uk Kim     {
399*0d84335fSJung-uk Kim         CvPrintOneCommentType (Op, AML_COMMENT_END_NODE, NULL, Level);
400*0d84335fSJung-uk Kim     }
401*0d84335fSJung-uk Kim     else if ((Op->Common.Parent->Common.AmlOpcode == AML_IF_OP) &&
402*0d84335fSJung-uk Kim          Op->Common.Parent->Common.EndNodeComment)
403*0d84335fSJung-uk Kim     {
404*0d84335fSJung-uk Kim         CvPrintOneCommentType (Op->Common.Parent,
405*0d84335fSJung-uk Kim             AML_COMMENT_END_NODE, NULL, Level);
406*0d84335fSJung-uk Kim     }
407*0d84335fSJung-uk Kim }
408*0d84335fSJung-uk Kim 
409*0d84335fSJung-uk Kim 
410*0d84335fSJung-uk Kim /*******************************************************************************
411*0d84335fSJung-uk Kim  *
412*0d84335fSJung-uk Kim  * FUNCTION:    CvFileHasSwitched
413*0d84335fSJung-uk Kim  *
414*0d84335fSJung-uk Kim  * PARAMETERS:  Op
415*0d84335fSJung-uk Kim  *
416*0d84335fSJung-uk Kim  * RETURN:      BOOLEAN
417*0d84335fSJung-uk Kim  *
418*0d84335fSJung-uk Kim  * DESCRIPTION: Determine whether if a file has switched.
419*0d84335fSJung-uk Kim  *              TRUE - file has switched.
420*0d84335fSJung-uk Kim  *              FALSE - file has not switched.
421*0d84335fSJung-uk Kim  *              This is referred as ASL_CV_FILE_HAS_SWITCHED.
422*0d84335fSJung-uk Kim  *
423*0d84335fSJung-uk Kim  ******************************************************************************/
424*0d84335fSJung-uk Kim 
425*0d84335fSJung-uk Kim BOOLEAN
426*0d84335fSJung-uk Kim CvFileHasSwitched(
427*0d84335fSJung-uk Kim     ACPI_PARSE_OBJECT       *Op)
428*0d84335fSJung-uk Kim {
429*0d84335fSJung-uk Kim     if (Op->Common.CvFilename   &&
430*0d84335fSJung-uk Kim         AcpiGbl_CurrentFilename &&
431*0d84335fSJung-uk Kim         AcpiUtStricmp(Op->Common.CvFilename, AcpiGbl_CurrentFilename))
432*0d84335fSJung-uk Kim     {
433*0d84335fSJung-uk Kim         return TRUE;
434*0d84335fSJung-uk Kim     }
435*0d84335fSJung-uk Kim     return FALSE;
436*0d84335fSJung-uk Kim }
437*0d84335fSJung-uk Kim 
438*0d84335fSJung-uk Kim 
439*0d84335fSJung-uk Kim /*******************************************************************************
440*0d84335fSJung-uk Kim  *
441*0d84335fSJung-uk Kim  * FUNCTION:    CvPrintInclude
442*0d84335fSJung-uk Kim  *
443*0d84335fSJung-uk Kim  * PARAMETERS:  FNode - Write an Include statement for the file that is pointed
444*0d84335fSJung-uk Kim  *                      by FNode->File.
445*0d84335fSJung-uk Kim  *              Level - indentation level
446*0d84335fSJung-uk Kim  *
447*0d84335fSJung-uk Kim  * RETURN:      None
448*0d84335fSJung-uk Kim  *
449*0d84335fSJung-uk Kim  * DESCRIPTION: Write the ASL Include statement for FNode->File in the file
450*0d84335fSJung-uk Kim  *              indicated by FNode->Parent->File. Note this function emits
451*0d84335fSJung-uk Kim  *              actual ASL code rather than comments. This switches the output
452*0d84335fSJung-uk Kim  *              file to FNode->Parent->File.
453*0d84335fSJung-uk Kim  *
454*0d84335fSJung-uk Kim  ******************************************************************************/
455*0d84335fSJung-uk Kim 
456*0d84335fSJung-uk Kim static void
457*0d84335fSJung-uk Kim CvPrintInclude(
458*0d84335fSJung-uk Kim     ACPI_FILE_NODE          *FNode,
459*0d84335fSJung-uk Kim     UINT32                  Level)
460*0d84335fSJung-uk Kim {
461*0d84335fSJung-uk Kim     if (!FNode || FNode->IncludeWritten)
462*0d84335fSJung-uk Kim     {
463*0d84335fSJung-uk Kim         return;
464*0d84335fSJung-uk Kim     }
465*0d84335fSJung-uk Kim 
466*0d84335fSJung-uk Kim     CvDbgPrint ("Writing include for %s within %s\n", FNode->Filename, FNode->Parent->Filename);
467*0d84335fSJung-uk Kim     AcpiOsRedirectOutput (FNode->Parent->File);
468*0d84335fSJung-uk Kim     CvPrintOneCommentList (FNode->IncludeComment, Level);
469*0d84335fSJung-uk Kim     AcpiDmIndent (Level);
470*0d84335fSJung-uk Kim     AcpiOsPrintf ("Include (\"%s\")\n", FNode->Filename);
471*0d84335fSJung-uk Kim     CvDbgPrint ("emitted the following: Include (\"%s\")\n", FNode->Filename);
472*0d84335fSJung-uk Kim     FNode->IncludeWritten = TRUE;
473*0d84335fSJung-uk Kim }
474*0d84335fSJung-uk Kim 
475*0d84335fSJung-uk Kim 
476*0d84335fSJung-uk Kim /*******************************************************************************
477*0d84335fSJung-uk Kim  *
478*0d84335fSJung-uk Kim  * FUNCTION:    CvSwitchFiles
479*0d84335fSJung-uk Kim  *
480*0d84335fSJung-uk Kim  * PARAMETERS:  Level - indentation level
481*0d84335fSJung-uk Kim  *              Op
482*0d84335fSJung-uk Kim  *
483*0d84335fSJung-uk Kim  * RETURN:      None
484*0d84335fSJung-uk Kim  *
485*0d84335fSJung-uk Kim  * DESCRIPTION: Switch the outputfile and write ASL Include statement. Note,
486*0d84335fSJung-uk Kim  *              this function emits actual ASL code rather than comments.
487*0d84335fSJung-uk Kim  *              This is referred as ASL_CV_SWITCH_FILES.
488*0d84335fSJung-uk Kim  *
489*0d84335fSJung-uk Kim  ******************************************************************************/
490*0d84335fSJung-uk Kim 
491*0d84335fSJung-uk Kim void
492*0d84335fSJung-uk Kim CvSwitchFiles(
493*0d84335fSJung-uk Kim     UINT32                  Level,
494*0d84335fSJung-uk Kim     ACPI_PARSE_OBJECT       *Op)
495*0d84335fSJung-uk Kim {
496*0d84335fSJung-uk Kim     char                    *Filename = Op->Common.CvFilename;
497*0d84335fSJung-uk Kim     ACPI_FILE_NODE          *FNode;
498*0d84335fSJung-uk Kim 
499*0d84335fSJung-uk Kim     CvDbgPrint ("Switching from %s to %s\n", AcpiGbl_CurrentFilename, Filename);
500*0d84335fSJung-uk Kim     FNode = CvFilenameExists (Filename, AcpiGbl_FileTreeRoot);
501*0d84335fSJung-uk Kim     if (!FNode)
502*0d84335fSJung-uk Kim     {
503*0d84335fSJung-uk Kim         /*
504*0d84335fSJung-uk Kim          * At this point, each Filename should exist in AcpiGbl_FileTreeRoot
505*0d84335fSJung-uk Kim          * if it does not exist, then abort.
506*0d84335fSJung-uk Kim          */
507*0d84335fSJung-uk Kim         FlDeleteFile (ASL_FILE_AML_OUTPUT);
508*0d84335fSJung-uk Kim         sprintf (MsgBuffer, "\"Cannot find %s\" - %s", Filename, strerror (errno));
509*0d84335fSJung-uk Kim         AslCommonError (ASL_ERROR, ASL_MSG_OPEN, 0, 0, 0, 0, NULL, MsgBuffer);
510*0d84335fSJung-uk Kim         AslAbort ();
511*0d84335fSJung-uk Kim     }
512*0d84335fSJung-uk Kim 
513*0d84335fSJung-uk Kim     /*
514*0d84335fSJung-uk Kim      * If the previous file is a descendent of the current file,
515*0d84335fSJung-uk Kim      * make sure that Include statements from the current file
516*0d84335fSJung-uk Kim      * to the previous have been emitted.
517*0d84335fSJung-uk Kim      */
518*0d84335fSJung-uk Kim     while (FNode &&
519*0d84335fSJung-uk Kim            FNode->Parent &&
520*0d84335fSJung-uk Kim            AcpiUtStricmp (FNode->Filename, AcpiGbl_CurrentFilename))
521*0d84335fSJung-uk Kim     {
522*0d84335fSJung-uk Kim         CvPrintInclude (FNode, Level);
523*0d84335fSJung-uk Kim         FNode = FNode->Parent;
524*0d84335fSJung-uk Kim     }
525*0d84335fSJung-uk Kim 
526*0d84335fSJung-uk Kim     /* Redirect output to the Op->Common.CvFilename */
527*0d84335fSJung-uk Kim 
528*0d84335fSJung-uk Kim     FNode = CvFilenameExists (Filename, AcpiGbl_FileTreeRoot);
529*0d84335fSJung-uk Kim     AcpiOsRedirectOutput (FNode->File);
530*0d84335fSJung-uk Kim     AcpiGbl_CurrentFilename = FNode->Filename;
531*0d84335fSJung-uk Kim }
532