1118611Snjl/******************************************************************************
2118611Snjl *
3118611Snjl * Module Name: aslcodegen - AML code generation
4118611Snjl *
5118611Snjl *****************************************************************************/
6118611Snjl
7217365Sjkim/*
8245582Sjkim * Copyright (C) 2000 - 2013, Intel Corp.
9118611Snjl * All rights reserved.
10118611Snjl *
11217365Sjkim * Redistribution and use in source and binary forms, with or without
12217365Sjkim * modification, are permitted provided that the following conditions
13217365Sjkim * are met:
14217365Sjkim * 1. Redistributions of source code must retain the above copyright
15217365Sjkim *    notice, this list of conditions, and the following disclaimer,
16217365Sjkim *    without modification.
17217365Sjkim * 2. Redistributions in binary form must reproduce at minimum a disclaimer
18217365Sjkim *    substantially similar to the "NO WARRANTY" disclaimer below
19217365Sjkim *    ("Disclaimer") and any redistribution must be conditioned upon
20217365Sjkim *    including a substantially similar Disclaimer requirement for further
21217365Sjkim *    binary redistribution.
22217365Sjkim * 3. Neither the names of the above-listed copyright holders nor the names
23217365Sjkim *    of any contributors may be used to endorse or promote products derived
24217365Sjkim *    from this software without specific prior written permission.
25118611Snjl *
26217365Sjkim * Alternatively, this software may be distributed under the terms of the
27217365Sjkim * GNU General Public License ("GPL") version 2 as published by the Free
28217365Sjkim * Software Foundation.
29118611Snjl *
30217365Sjkim * NO WARRANTY
31217365Sjkim * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
32217365Sjkim * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
33217365Sjkim * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
34217365Sjkim * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
35217365Sjkim * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
36217365Sjkim * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
37217365Sjkim * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
38217365Sjkim * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
39217365Sjkim * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
40217365Sjkim * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
41217365Sjkim * POSSIBILITY OF SUCH DAMAGES.
42217365Sjkim */
43118611Snjl
44118611Snjl
45151937Sjkim#include <contrib/dev/acpica/compiler/aslcompiler.h>
46118611Snjl#include "aslcompiler.y.h"
47193529Sjkim#include <contrib/dev/acpica/include/amlcode.h>
48118611Snjl
49118611Snjl#define _COMPONENT          ACPI_COMPILER
50118611Snjl        ACPI_MODULE_NAME    ("aslcodegen")
51118611Snjl
52151937Sjkim/* Local prototypes */
53118611Snjl
54151937Sjkimstatic ACPI_STATUS
55151937SjkimCgAmlWriteWalk (
56151937Sjkim    ACPI_PARSE_OBJECT       *Op,
57151937Sjkim    UINT32                  Level,
58151937Sjkim    void                    *Context);
59151937Sjkim
60151937Sjkimstatic void
61151937SjkimCgLocalWriteAmlData (
62151937Sjkim    ACPI_PARSE_OBJECT       *Op,
63151937Sjkim    void                    *Buffer,
64151937Sjkim    UINT32                  Length);
65151937Sjkim
66151937Sjkimstatic void
67151937SjkimCgWriteAmlOpcode (
68151937Sjkim    ACPI_PARSE_OBJECT       *Op);
69151937Sjkim
70151937Sjkimstatic void
71151937SjkimCgWriteTableHeader (
72151937Sjkim    ACPI_PARSE_OBJECT       *Op);
73151937Sjkim
74151937Sjkimstatic void
75151937SjkimCgCloseTable (
76151937Sjkim    void);
77151937Sjkim
78151937Sjkimstatic void
79151937SjkimCgWriteNode (
80151937Sjkim    ACPI_PARSE_OBJECT       *Op);
81151937Sjkim
82151937Sjkim
83118611Snjl/*******************************************************************************
84118611Snjl *
85118611Snjl * FUNCTION:    CgGenerateAmlOutput
86118611Snjl *
87118611Snjl * PARAMETERS:  None.
88118611Snjl *
89118611Snjl * RETURN:      None
90118611Snjl *
91241973Sjkim * DESCRIPTION: Generate AML code. Currently generates the listing file
92118611Snjl *              simultaneously.
93118611Snjl *
94118611Snjl ******************************************************************************/
95118611Snjl
96118611Snjlvoid
97151937SjkimCgGenerateAmlOutput (
98151937Sjkim    void)
99118611Snjl{
100118611Snjl
101118611Snjl    DbgPrint (ASL_DEBUG_OUTPUT, "\nWriting AML\n\n");
102118611Snjl
103118611Snjl    /* Generate the AML output file */
104118611Snjl
105118611Snjl    FlSeekFile (ASL_FILE_SOURCE_OUTPUT, 0);
106118611Snjl    Gbl_SourceLine = 0;
107118611Snjl    Gbl_NextError = Gbl_ErrorLog;
108118611Snjl
109151937Sjkim    TrWalkParseTree (RootNode, ASL_WALK_VISIT_DOWNWARD,
110151937Sjkim        CgAmlWriteWalk, NULL, NULL);
111118611Snjl    CgCloseTable ();
112118611Snjl}
113118611Snjl
114118611Snjl
115118611Snjl/*******************************************************************************
116118611Snjl *
117118611Snjl * FUNCTION:    CgAmlWriteWalk
118118611Snjl *
119118611Snjl * PARAMETERS:  ASL_WALK_CALLBACK
120118611Snjl *
121118611Snjl * RETURN:      Status
122118611Snjl *
123118611Snjl * DESCRIPTION: Parse tree walk to generate the AML code.
124118611Snjl *
125118611Snjl ******************************************************************************/
126118611Snjl
127151937Sjkimstatic ACPI_STATUS
128118611SnjlCgAmlWriteWalk (
129118611Snjl    ACPI_PARSE_OBJECT       *Op,
130118611Snjl    UINT32                  Level,
131118611Snjl    void                    *Context)
132118611Snjl{
133118611Snjl
134167802Sjkim    /*
135167802Sjkim     * Print header at level 0. Alignment assumes 32-bit pointers
136167802Sjkim     */
137167802Sjkim    if (!Level)
138167802Sjkim    {
139167802Sjkim        DbgPrint (ASL_TREE_OUTPUT,
140167802Sjkim            "Final parse tree used for AML output:\n");
141167802Sjkim        DbgPrint (ASL_TREE_OUTPUT,
142167802Sjkim            "%*s Value    P_Op A_Op OpLen PByts Len  SubLen PSubLen OpPtr    Child    Parent   Flags    AcTyp    Final Col L\n",
143167802Sjkim            76, " ");
144167802Sjkim    }
145167802Sjkim
146151937Sjkim    /* Debug output */
147151937Sjkim
148118611Snjl    DbgPrint (ASL_TREE_OUTPUT,
149118611Snjl        "%5.5d [%2d]", Op->Asl.LogicalLineNumber, Level);
150118611Snjl    UtPrintFormattedName (Op->Asl.ParseOpcode, Level);
151118611Snjl
152118611Snjl    if (Op->Asl.ParseOpcode == PARSEOP_NAMESEG    ||
153118611Snjl        Op->Asl.ParseOpcode == PARSEOP_NAMESTRING ||
154118611Snjl        Op->Asl.ParseOpcode == PARSEOP_METHODCALL)
155118611Snjl    {
156118611Snjl        DbgPrint (ASL_TREE_OUTPUT,
157118611Snjl            "%10.32s      ", Op->Asl.ExternalName);
158118611Snjl    }
159118611Snjl    else
160118611Snjl    {
161118611Snjl        DbgPrint (ASL_TREE_OUTPUT, "                ");
162118611Snjl    }
163118611Snjl
164193529Sjkim    DbgPrint (ASL_TREE_OUTPUT,
165193529Sjkim    "%08X %04X %04X %01X     %04X  %04X %04X   %04X    %08X %08X %08X %08X %08X %04X  %02d  %02d\n",
166193529Sjkim            /* 1  */ (UINT32) Op->Asl.Value.Integer,
167193529Sjkim            /* 2  */ Op->Asl.ParseOpcode,
168193529Sjkim            /* 3  */ Op->Asl.AmlOpcode,
169193529Sjkim            /* 4  */ Op->Asl.AmlOpcodeLength,
170193529Sjkim            /* 5  */ Op->Asl.AmlPkgLenBytes,
171193529Sjkim            /* 6  */ Op->Asl.AmlLength,
172193529Sjkim            /* 7  */ Op->Asl.AmlSubtreeLength,
173193529Sjkim            /* 8  */ Op->Asl.Parent ? Op->Asl.Parent->Asl.AmlSubtreeLength : 0,
174193529Sjkim            /* 9  */ Op,
175193529Sjkim            /* 10 */ Op->Asl.Child,
176193529Sjkim            /* 11 */ Op->Asl.Parent,
177193529Sjkim            /* 12 */ Op->Asl.CompileFlags,
178193529Sjkim            /* 13 */ Op->Asl.AcpiBtype,
179193529Sjkim            /* 14 */ Op->Asl.FinalAmlLength,
180193529Sjkim            /* 15 */ Op->Asl.Column,
181193529Sjkim            /* 16 */ Op->Asl.LineNumber);
182118611Snjl
183151937Sjkim    /* Generate the AML for this node */
184151937Sjkim
185118611Snjl    CgWriteNode (Op);
186118611Snjl    return (AE_OK);
187118611Snjl}
188118611Snjl
189118611Snjl
190118611Snjl/*******************************************************************************
191118611Snjl *
192118611Snjl * FUNCTION:    CgLocalWriteAmlData
193118611Snjl *
194151937Sjkim * PARAMETERS:  Op              - Current parse op
195151937Sjkim *              Buffer          - Buffer to write
196118611Snjl *              Length          - Size of data in buffer
197118611Snjl *
198118611Snjl * RETURN:      None
199118611Snjl *
200118611Snjl * DESCRIPTION: Write a buffer of AML data to the AML output file.
201118611Snjl *
202118611Snjl ******************************************************************************/
203118611Snjl
204151937Sjkimstatic void
205118611SnjlCgLocalWriteAmlData (
206118611Snjl    ACPI_PARSE_OBJECT       *Op,
207118611Snjl    void                    *Buffer,
208118611Snjl    UINT32                  Length)
209118611Snjl{
210118611Snjl
211118611Snjl    /* Write the raw data to the AML file */
212118611Snjl
213118611Snjl    FlWriteFile (ASL_FILE_AML_OUTPUT, Buffer, Length);
214118611Snjl
215118611Snjl    /* Update the final AML length for this node (used for listings) */
216118611Snjl
217118611Snjl    if (Op)
218118611Snjl    {
219118611Snjl        Op->Asl.FinalAmlLength += Length;
220118611Snjl    }
221118611Snjl}
222118611Snjl
223118611Snjl
224118611Snjl/*******************************************************************************
225118611Snjl *
226118611Snjl * FUNCTION:    CgWriteAmlOpcode
227118611Snjl *
228118611Snjl * PARAMETERS:  Op            - Parse node with an AML opcode
229118611Snjl *
230118611Snjl * RETURN:      None.
231118611Snjl *
232118611Snjl * DESCRIPTION: Write the AML opcode corresponding to a parse node.
233118611Snjl *
234118611Snjl ******************************************************************************/
235118611Snjl
236151937Sjkimstatic void
237118611SnjlCgWriteAmlOpcode (
238151937Sjkim    ACPI_PARSE_OBJECT       *Op)
239118611Snjl{
240151937Sjkim    UINT8                   PkgLenFirstByte;
241151937Sjkim    UINT32                  i;
242118611Snjl    union {
243151937Sjkim        UINT16                  Opcode;
244151937Sjkim        UINT8                   OpcodeBytes[2];
245118611Snjl    } Aml;
246118611Snjl    union {
247151937Sjkim        UINT32                  Len;
248151937Sjkim        UINT8                   LenBytes[4];
249118611Snjl    } PkgLen;
250118611Snjl
251118611Snjl
252118611Snjl    /* We expect some DEFAULT_ARGs, just ignore them */
253118611Snjl
254118611Snjl    if (Op->Asl.ParseOpcode == PARSEOP_DEFAULT_ARG)
255118611Snjl    {
256118611Snjl        return;
257118611Snjl    }
258118611Snjl
259118611Snjl    switch (Op->Asl.AmlOpcode)
260118611Snjl    {
261118611Snjl    case AML_UNASSIGNED_OPCODE:
262118611Snjl
263118611Snjl        /* These opcodes should not get here */
264118611Snjl
265118611Snjl        printf ("Found a node with an unassigned AML opcode\n");
266233250Sjkim        FlPrintFile (ASL_FILE_STDERR, "Found a node with an unassigned AML opcode\n");
267118611Snjl        return;
268118611Snjl
269118611Snjl    case AML_INT_RESERVEDFIELD_OP:
270118611Snjl
271118611Snjl        /* Special opcodes for within a field definition */
272118611Snjl
273228110Sjkim        Aml.Opcode = AML_FIELD_OFFSET_OP;
274118611Snjl        break;
275118611Snjl
276118611Snjl    case AML_INT_ACCESSFIELD_OP:
277118611Snjl
278228110Sjkim        Aml.Opcode = AML_FIELD_ACCESS_OP;
279118611Snjl        break;
280118611Snjl
281228110Sjkim    case AML_INT_CONNECTION_OP:
282228110Sjkim
283228110Sjkim        Aml.Opcode = AML_FIELD_CONNECTION_OP;
284228110Sjkim        break;
285228110Sjkim
286118611Snjl    default:
287250838Sjkim
288118611Snjl        Aml.Opcode = Op->Asl.AmlOpcode;
289118611Snjl        break;
290118611Snjl    }
291118611Snjl
292118611Snjl
293118611Snjl    switch (Aml.Opcode)
294118611Snjl    {
295118611Snjl    case AML_PACKAGE_LENGTH:
296118611Snjl
297118611Snjl        /* Value is the length to be encoded (Used in field definitions) */
298118611Snjl
299118611Snjl        PkgLen.Len = (UINT32) Op->Asl.Value.Integer;
300118611Snjl        break;
301118611Snjl
302118611Snjl    default:
303118611Snjl
304118611Snjl        /* Check for two-byte opcode */
305118611Snjl
306118611Snjl        if (Aml.Opcode > 0x00FF)
307118611Snjl        {
308118611Snjl            /* Write the high byte first */
309118611Snjl
310118611Snjl            CgLocalWriteAmlData (Op, &Aml.OpcodeBytes[1], 1);
311118611Snjl        }
312118611Snjl
313118611Snjl        CgLocalWriteAmlData (Op, &Aml.OpcodeBytes[0], 1);
314118611Snjl
315118611Snjl        /* Subtreelength doesn't include length of package length bytes */
316118611Snjl
317118611Snjl        PkgLen.Len = Op->Asl.AmlSubtreeLength + Op->Asl.AmlPkgLenBytes;
318118611Snjl        break;
319118611Snjl    }
320118611Snjl
321118611Snjl    /* Does this opcode have an associated "PackageLength" field? */
322118611Snjl
323118611Snjl    if (Op->Asl.CompileFlags & NODE_AML_PACKAGE)
324118611Snjl    {
325118611Snjl        if (Op->Asl.AmlPkgLenBytes == 1)
326118611Snjl        {
327118611Snjl            /* Simplest case -- no bytes to follow, just write the count */
328118611Snjl
329118611Snjl            CgLocalWriteAmlData (Op, &PkgLen.LenBytes[0], 1);
330118611Snjl        }
331167802Sjkim        else if (Op->Asl.AmlPkgLenBytes != 0)
332118611Snjl        {
333118611Snjl            /*
334118611Snjl             * Encode the "bytes to follow" in the first byte, top two bits.
335118611Snjl             * The low-order nybble of the length is in the bottom 4 bits
336118611Snjl             */
337151937Sjkim            PkgLenFirstByte = (UINT8)
338151937Sjkim                (((UINT32) (Op->Asl.AmlPkgLenBytes - 1) << 6) |
339151937Sjkim                (PkgLen.LenBytes[0] & 0x0F));
340118611Snjl
341118611Snjl            CgLocalWriteAmlData (Op, &PkgLenFirstByte, 1);
342118611Snjl
343151937Sjkim            /*
344151937Sjkim             * Shift the length over by the 4 bits we just stuffed
345151937Sjkim             * in the first byte
346151937Sjkim             */
347118611Snjl            PkgLen.Len >>= 4;
348118611Snjl
349118611Snjl            /* Now we can write the remaining bytes - either 1, 2, or 3 bytes */
350118611Snjl
351118611Snjl            for (i = 0; i < (UINT32) (Op->Asl.AmlPkgLenBytes - 1); i++)
352118611Snjl            {
353118611Snjl                CgLocalWriteAmlData (Op, &PkgLen.LenBytes[i], 1);
354118611Snjl            }
355118611Snjl        }
356118611Snjl    }
357118611Snjl
358118611Snjl    switch (Aml.Opcode)
359118611Snjl    {
360118611Snjl    case AML_BYTE_OP:
361118611Snjl
362151937Sjkim        CgLocalWriteAmlData (Op, &Op->Asl.Value.Integer, 1);
363118611Snjl        break;
364118611Snjl
365118611Snjl    case AML_WORD_OP:
366118611Snjl
367151937Sjkim        CgLocalWriteAmlData (Op, &Op->Asl.Value.Integer, 2);
368118611Snjl       break;
369118611Snjl
370118611Snjl    case AML_DWORD_OP:
371118611Snjl
372151937Sjkim        CgLocalWriteAmlData (Op, &Op->Asl.Value.Integer, 4);
373118611Snjl        break;
374118611Snjl
375118611Snjl    case AML_QWORD_OP:
376118611Snjl
377118611Snjl        CgLocalWriteAmlData (Op, &Op->Asl.Value.Integer, 8);
378118611Snjl        break;
379118611Snjl
380118611Snjl    case AML_STRING_OP:
381118611Snjl
382118611Snjl        CgLocalWriteAmlData (Op, Op->Asl.Value.String, Op->Asl.AmlLength);
383118611Snjl        break;
384118611Snjl
385118611Snjl    default:
386250838Sjkim
387118611Snjl        /* All data opcodes must appear above */
388250838Sjkim
389118611Snjl        break;
390118611Snjl    }
391118611Snjl}
392118611Snjl
393118611Snjl
394118611Snjl/*******************************************************************************
395118611Snjl *
396118611Snjl * FUNCTION:    CgWriteTableHeader
397118611Snjl *
398118611Snjl * PARAMETERS:  Op        - The DEFINITIONBLOCK node
399118611Snjl *
400151937Sjkim * RETURN:      None
401118611Snjl *
402118611Snjl * DESCRIPTION: Write a table header corresponding to the DEFINITIONBLOCK
403118611Snjl *
404118611Snjl ******************************************************************************/
405118611Snjl
406151937Sjkimstatic void
407118611SnjlCgWriteTableHeader (
408151937Sjkim    ACPI_PARSE_OBJECT       *Op)
409118611Snjl{
410151937Sjkim    ACPI_PARSE_OBJECT       *Child;
411118611Snjl
412118611Snjl
413118611Snjl    /* AML filename */
414118611Snjl
415118611Snjl    Child = Op->Asl.Child;
416118611Snjl
417118611Snjl    /* Signature */
418118611Snjl
419118611Snjl    Child = Child->Asl.Next;
420118611Snjl    strncpy (TableHeader.Signature, Child->Asl.Value.String, 4);
421118611Snjl
422118611Snjl    /* Revision */
423118611Snjl
424118611Snjl    Child = Child->Asl.Next;
425118611Snjl    TableHeader.Revision = (UINT8) Child->Asl.Value.Integer;
426118611Snjl
427138287Smarks    /* Command-line Revision override */
428138287Smarks
429138287Smarks    if (Gbl_RevisionOverride)
430138287Smarks    {
431138287Smarks        TableHeader.Revision = Gbl_RevisionOverride;
432138287Smarks    }
433138287Smarks
434118611Snjl    /* OEMID */
435118611Snjl
436118611Snjl    Child = Child->Asl.Next;
437118611Snjl    strncpy (TableHeader.OemId, Child->Asl.Value.String, 6);
438118611Snjl
439118611Snjl    /* OEM TableID */
440118611Snjl
441118611Snjl    Child = Child->Asl.Next;
442118611Snjl    strncpy (TableHeader.OemTableId, Child->Asl.Value.String, 8);
443118611Snjl
444118611Snjl    /* OEM Revision */
445118611Snjl
446118611Snjl    Child = Child->Asl.Next;
447118611Snjl    TableHeader.OemRevision = (UINT32) Child->Asl.Value.Integer;
448118611Snjl
449118611Snjl    /* Compiler ID */
450118611Snjl
451241973Sjkim    ACPI_MOVE_NAME (TableHeader.AslCompilerId, ASL_CREATOR_ID);
452118611Snjl
453118611Snjl    /* Compiler version */
454118611Snjl
455213806Sjkim    TableHeader.AslCompilerRevision = ASL_REVISION;
456118611Snjl
457151937Sjkim    /* Table length. Checksum zero for now, will rewrite later */
458118611Snjl
459118611Snjl    TableHeader.Length   = Gbl_TableLength;
460118611Snjl    TableHeader.Checksum = 0;
461118611Snjl
462118611Snjl    CgLocalWriteAmlData (Op, &TableHeader, sizeof (ACPI_TABLE_HEADER));
463118611Snjl}
464118611Snjl
465118611Snjl
466118611Snjl/*******************************************************************************
467118611Snjl *
468118611Snjl * FUNCTION:    CgCloseTable
469118611Snjl *
470118611Snjl * PARAMETERS:  None.
471118611Snjl *
472118611Snjl * RETURN:      None.
473118611Snjl *
474118611Snjl * DESCRIPTION: Complete the ACPI table by calculating the checksum and
475118611Snjl *              re-writing the header.
476118611Snjl *
477118611Snjl ******************************************************************************/
478118611Snjl
479151937Sjkimstatic void
480151937SjkimCgCloseTable (
481151937Sjkim    void)
482118611Snjl{
483118611Snjl    signed char         Sum;
484118611Snjl    UINT8               FileByte;
485118611Snjl
486118611Snjl
487118611Snjl    FlSeekFile (ASL_FILE_AML_OUTPUT, 0);
488118611Snjl    Sum = 0;
489118611Snjl
490118611Snjl    /* Calculate the checksum over the entire file */
491118611Snjl
492118611Snjl    while (FlReadFile (ASL_FILE_AML_OUTPUT, &FileByte, 1) == AE_OK)
493118611Snjl    {
494118611Snjl        Sum = (signed char) (Sum + FileByte);
495118611Snjl    }
496118611Snjl
497118611Snjl    /* Re-write the table header with the checksum */
498118611Snjl
499118611Snjl    TableHeader.Checksum = (UINT8) (0 - Sum);
500118611Snjl
501118611Snjl    FlSeekFile (ASL_FILE_AML_OUTPUT, 0);
502118611Snjl    CgLocalWriteAmlData (NULL, &TableHeader, sizeof (ACPI_TABLE_HEADER));
503118611Snjl}
504118611Snjl
505118611Snjl
506118611Snjl/*******************************************************************************
507118611Snjl *
508118611Snjl * FUNCTION:    CgWriteNode
509118611Snjl *
510118611Snjl * PARAMETERS:  Op            - Parse node to write.
511118611Snjl *
512118611Snjl * RETURN:      None.
513118611Snjl *
514118611Snjl * DESCRIPTION: Write the AML that corresponds to a parse node.
515118611Snjl *
516118611Snjl ******************************************************************************/
517118611Snjl
518151937Sjkimstatic void
519118611SnjlCgWriteNode (
520118611Snjl    ACPI_PARSE_OBJECT       *Op)
521118611Snjl{
522118611Snjl    ASL_RESOURCE_NODE       *Rnode;
523118611Snjl
524118611Snjl
525118611Snjl    /* Always check for DEFAULT_ARG and other "Noop" nodes */
526118611Snjl    /* TBD: this may not be the best place for this check */
527118611Snjl
528118611Snjl    if ((Op->Asl.ParseOpcode == PARSEOP_DEFAULT_ARG)  ||
529118611Snjl        (Op->Asl.ParseOpcode == PARSEOP_EXTERNAL)     ||
530118611Snjl        (Op->Asl.ParseOpcode == PARSEOP_INCLUDE)      ||
531118611Snjl        (Op->Asl.ParseOpcode == PARSEOP_INCLUDE_END))
532118611Snjl    {
533118611Snjl        return;
534118611Snjl    }
535118611Snjl
536167802Sjkim    Op->Asl.FinalAmlLength = 0;
537167802Sjkim
538118611Snjl    switch (Op->Asl.AmlOpcode)
539118611Snjl    {
540118611Snjl    case AML_RAW_DATA_BYTE:
541118611Snjl    case AML_RAW_DATA_WORD:
542118611Snjl    case AML_RAW_DATA_DWORD:
543118611Snjl    case AML_RAW_DATA_QWORD:
544118611Snjl
545118611Snjl        CgLocalWriteAmlData (Op, &Op->Asl.Value.Integer, Op->Asl.AmlLength);
546118611Snjl        return;
547118611Snjl
548118611Snjl
549118611Snjl    case AML_RAW_DATA_BUFFER:
550118611Snjl
551118611Snjl        CgLocalWriteAmlData (Op, Op->Asl.Value.Buffer, Op->Asl.AmlLength);
552118611Snjl        return;
553118611Snjl
554118611Snjl
555118611Snjl    case AML_RAW_DATA_CHAIN:
556118611Snjl
557118611Snjl        Rnode = ACPI_CAST_PTR (ASL_RESOURCE_NODE, Op->Asl.Value.Buffer);
558118611Snjl        while (Rnode)
559118611Snjl        {
560118611Snjl            CgLocalWriteAmlData (Op, Rnode->Buffer, Rnode->BufferLength);
561118611Snjl            Rnode = Rnode->Next;
562118611Snjl        }
563118611Snjl        return;
564118611Snjl
565118611Snjl    default:
566250838Sjkim
567118611Snjl        /* Internal data opcodes must all appear above */
568250838Sjkim
569118611Snjl        break;
570118611Snjl    }
571118611Snjl
572118611Snjl    switch (Op->Asl.ParseOpcode)
573118611Snjl    {
574118611Snjl    case PARSEOP_DEFAULT_ARG:
575118611Snjl
576118611Snjl        break;
577118611Snjl
578118611Snjl    case PARSEOP_DEFINITIONBLOCK:
579118611Snjl
580118611Snjl        CgWriteTableHeader (Op);
581118611Snjl        break;
582118611Snjl
583118611Snjl    case PARSEOP_NAMESEG:
584118611Snjl    case PARSEOP_NAMESTRING:
585118611Snjl    case PARSEOP_METHODCALL:
586118611Snjl
587118611Snjl        CgLocalWriteAmlData (Op, Op->Asl.Value.String, Op->Asl.AmlLength);
588118611Snjl        break;
589118611Snjl
590118611Snjl    default:
591118611Snjl
592118611Snjl        CgWriteAmlOpcode (Op);
593118611Snjl        break;
594118611Snjl    }
595118611Snjl}
596