Path: blob/main/sys/contrib/dev/acpica/compiler/aslcodegen.c
48371 views
/******************************************************************************1*2* Module Name: aslcodegen - AML code generation3*4*****************************************************************************/56/******************************************************************************7*8* 1. Copyright Notice9*10* Some or all of this work - Copyright (c) 1999 - 2025, Intel Corp.11* All rights reserved.12*13* 2. License14*15* 2.1. This is your license from Intel Corp. under its intellectual property16* rights. You may have additional license terms from the party that provided17* you this software, covering your right to use that party's intellectual18* property rights.19*20* 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a21* copy of the source code appearing in this file ("Covered Code") an22* irrevocable, perpetual, worldwide license under Intel's copyrights in the23* base code distributed originally by Intel ("Original Intel Code") to copy,24* make derivatives, distribute, use and display any portion of the Covered25* Code in any form, with the right to sublicense such rights; and26*27* 2.3. Intel grants Licensee a non-exclusive and non-transferable patent28* license (with the right to sublicense), under only those claims of Intel29* patents that are infringed by the Original Intel Code, to make, use, sell,30* offer to sell, and import the Covered Code and derivative works thereof31* solely to the minimum extent necessary to exercise the above copyright32* license, and in no event shall the patent license extend to any additions33* to or modifications of the Original Intel Code. No other license or right34* is granted directly or by implication, estoppel or otherwise;35*36* The above copyright and patent license is granted only if the following37* conditions are met:38*39* 3. Conditions40*41* 3.1. Redistribution of Source with Rights to Further Distribute Source.42* Redistribution of source code of any substantial portion of the Covered43* Code or modification with rights to further distribute source must include44* the above Copyright Notice, the above License, this list of Conditions,45* and the following Disclaimer and Export Compliance provision. In addition,46* Licensee must cause all Covered Code to which Licensee contributes to47* contain a file documenting the changes Licensee made to create that Covered48* Code and the date of any change. Licensee must include in that file the49* documentation of any changes made by any predecessor Licensee. Licensee50* must include a prominent statement that the modification is derived,51* directly or indirectly, from Original Intel Code.52*53* 3.2. Redistribution of Source with no Rights to Further Distribute Source.54* Redistribution of source code of any substantial portion of the Covered55* Code or modification without rights to further distribute source must56* include the following Disclaimer and Export Compliance provision in the57* documentation and/or other materials provided with distribution. In58* addition, Licensee may not authorize further sublicense of source of any59* portion of the Covered Code, and must include terms to the effect that the60* license from Licensee to its licensee is limited to the intellectual61* property embodied in the software Licensee provides to its licensee, and62* not to intellectual property embodied in modifications its licensee may63* make.64*65* 3.3. Redistribution of Executable. Redistribution in executable form of any66* substantial portion of the Covered Code or modification must reproduce the67* above Copyright Notice, and the following Disclaimer and Export Compliance68* provision in the documentation and/or other materials provided with the69* distribution.70*71* 3.4. Intel retains all right, title, and interest in and to the Original72* Intel Code.73*74* 3.5. Neither the name Intel nor any other trademark owned or controlled by75* Intel shall be used in advertising or otherwise to promote the sale, use or76* other dealings in products derived from or relating to the Covered Code77* without prior written authorization from Intel.78*79* 4. Disclaimer and Export Compliance80*81* 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED82* HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE83* IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE,84* INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY85* UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY86* IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A87* PARTICULAR PURPOSE.88*89* 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES90* OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR91* COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,92* SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY93* CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL94* HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS95* SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY96* LIMITED REMEDY.97*98* 4.3. Licensee shall not export, either directly or indirectly, any of this99* software or system incorporating such software without first obtaining any100* required license or other approval from the U. S. Department of Commerce or101* any other agency or department of the United States Government. In the102* event Licensee exports any such software from the United States or103* re-exports any such software from a foreign destination, Licensee shall104* ensure that the distribution and export/re-export of the software is in105* compliance with all laws, regulations, orders, or other restrictions of the106* U.S. Export Administration Regulations. Licensee agrees that neither it nor107* any of its subsidiaries will export/re-export any technical data, process,108* software, or service, directly or indirectly, to any country for which the109* United States government or any agency thereof requires an export license,110* other governmental approval, or letter of assurance, without first obtaining111* such license, approval or letter.112*113*****************************************************************************114*115* Alternatively, you may choose to be licensed under the terms of the116* following license:117*118* Redistribution and use in source and binary forms, with or without119* modification, are permitted provided that the following conditions120* are met:121* 1. Redistributions of source code must retain the above copyright122* notice, this list of conditions, and the following disclaimer,123* without modification.124* 2. Redistributions in binary form must reproduce at minimum a disclaimer125* substantially similar to the "NO WARRANTY" disclaimer below126* ("Disclaimer") and any redistribution must be conditioned upon127* including a substantially similar Disclaimer requirement for further128* binary redistribution.129* 3. Neither the names of the above-listed copyright holders nor the names130* of any contributors may be used to endorse or promote products derived131* from this software without specific prior written permission.132*133* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS134* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT135* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR136* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT137* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,138* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT139* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,140* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY141* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT142* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE143* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.144*145* Alternatively, you may choose to be licensed under the terms of the146* GNU General Public License ("GPL") version 2 as published by the Free147* Software Foundation.148*149*****************************************************************************/150151#include <contrib/dev/acpica/compiler/aslcompiler.h>152#include "aslcompiler.y.h"153#include <contrib/dev/acpica/include/amlcode.h>154#include <contrib/dev/acpica/include/acconvert.h>155#include <contrib/dev/acpica/include/actbinfo.h>156157#define _COMPONENT ACPI_COMPILER158ACPI_MODULE_NAME ("aslcodegen")159160/* Local prototypes */161162static ACPI_STATUS163CgAmlWriteWalk (164ACPI_PARSE_OBJECT *Op,165UINT32 Level,166void *Context);167168static void169CgWriteAmlOpcode (170ACPI_PARSE_OBJECT *Op);171172static void173CgWriteTableHeader (174ACPI_PARSE_OBJECT *Op);175176static void177CgWriteNode (178ACPI_PARSE_OBJECT *Op);179180static void181CgUpdateHeader (182ACPI_PARSE_OBJECT *Op);183184static void185CgUpdateCdatHeader (186ACPI_PARSE_OBJECT *Op);187188189/*******************************************************************************190*191* FUNCTION: CgGenerateAmlOutput192*193* PARAMETERS: None.194*195* RETURN: None196*197* DESCRIPTION: Generate AML code. Currently generates the listing file198* simultaneously.199*200******************************************************************************/201202void203CgGenerateAmlOutput (204void)205{206207/* Generate the AML output file */208209TrWalkParseTree (AslGbl_CurrentDB,210ASL_WALK_VISIT_DOWNWARD | ASL_WALK_VISIT_DB_SEPARATELY,211CgAmlWriteWalk, NULL, NULL);212213DbgPrint (ASL_TREE_OUTPUT, ASL_PARSE_TREE_HEADER2);214if (AcpiGbl_CDAT)215{216CgUpdateCdatHeader (AslGbl_CurrentDB);217}218else219{220CgUpdateHeader (AslGbl_CurrentDB);221}222}223224225/*******************************************************************************226*227* FUNCTION: CgAmlWriteWalk228*229* PARAMETERS: ASL_WALK_CALLBACK230*231* RETURN: Status232*233* DESCRIPTION: Parse tree walk to generate the AML code.234*235******************************************************************************/236237static ACPI_STATUS238CgAmlWriteWalk (239ACPI_PARSE_OBJECT *Op,240UINT32 Level,241void *Context)242{243244/* Generate the AML for this node */245246CgWriteNode (Op);247248if (!AslGbl_DebugFlag)249{250return (AE_OK);251}252253/* Print header at level 0. Alignment assumes 32-bit pointers */254255if (!Level)256{257DbgPrint (ASL_TREE_OUTPUT,258"\nFinal parse tree used for AML output:\n");259DbgPrint (ASL_TREE_OUTPUT, ASL_PARSE_TREE_HEADER2);260}261262/* Dump ParseOp name and possible value */263264switch (Op->Asl.ParseOpcode)265{266case PARSEOP_NAMESEG:267case PARSEOP_NAMESTRING:268case PARSEOP_METHODCALL:269case PARSEOP_STRING_LITERAL:270271UtDumpStringOp (Op, Level);272break;273274default:275276UtDumpBasicOp (Op, Level);277break;278}279280DbgPrint (ASL_TREE_OUTPUT, ASL_PARSE_TREE_DEBUG2,281/* 1 */ (UINT32) Op->Asl.Value.Integer,282/* 2 */ Op->Asl.ParseOpcode,283/* 3 */ Op->Asl.AmlOpcode,284/* 4 */ Op->Asl.AmlOpcodeLength,285/* 5 */ Op->Asl.AmlPkgLenBytes,286/* 6 */ Op->Asl.AmlLength,287/* 7 */ Op->Asl.AmlSubtreeLength,288/* 8 */ Op->Asl.Parent ? Op->Asl.Parent->Asl.AmlSubtreeLength : 0,289/* 9 */ Op,290/* 10 */ Op->Asl.Parent,291/* 11 */ Op->Asl.Child,292/* 12 */ Op->Asl.Next,293/* 13 */ Op->Asl.CompileFlags,294/* 14 */ Op->Asl.AcpiBtype,295/* 15 */ Op->Asl.FinalAmlLength,296/* 16 */ Op->Asl.Column,297/* 17 */ Op->Asl.LineNumber,298/* 18 */ Op->Asl.EndLine,299/* 19 */ Op->Asl.LogicalLineNumber,300/* 20 */ Op->Asl.EndLogicalLine);301302TrPrintOpFlags (Op->Asl.CompileFlags, ASL_TREE_OUTPUT);303DbgPrint (ASL_TREE_OUTPUT, "\n");304return (AE_OK);305}306307308/*******************************************************************************309*310* FUNCTION: CgLocalWriteAmlData311*312* PARAMETERS: Op - Current parse op313* Buffer - Buffer to write314* Length - Size of data in buffer315*316* RETURN: None317*318* DESCRIPTION: Write a buffer of AML data to the AML output file.319*320******************************************************************************/321322void323CgLocalWriteAmlData (324ACPI_PARSE_OBJECT *Op,325void *Buffer,326UINT32 Length)327{328329/* Write the raw data to the AML file */330331FlWriteFile (ASL_FILE_AML_OUTPUT, Buffer, Length);332333/* Update the final AML length for this node (used for listings) */334335if (Op)336{337Op->Asl.FinalAmlLength += Length;338}339}340341342/*******************************************************************************343*344* FUNCTION: CgWriteAmlOpcode345*346* PARAMETERS: Op - Parse node with an AML opcode347*348* RETURN: None.349*350* DESCRIPTION: Write the AML opcode corresponding to a parse node.351*352******************************************************************************/353354static void355CgWriteAmlOpcode (356ACPI_PARSE_OBJECT *Op)357{358UINT8 PkgLenFirstByte;359UINT32 i;360union {361UINT16 Opcode;362UINT8 OpcodeBytes[2];363} Aml;364union {365UINT32 Len;366UINT8 LenBytes[4];367} PkgLen;368369370/* We expect some DEFAULT_ARGs, just ignore them */371372if (Op->Asl.ParseOpcode == PARSEOP_DEFAULT_ARG)373{374return;375}376377/*378* Before printing the bytecode, generate comment byte codes379* associated with this node.380*/381if (AcpiGbl_CaptureComments)382{383CgWriteAmlComment(Op);384}385386switch (Op->Asl.AmlOpcode)387{388case AML_UNASSIGNED_OPCODE:389390/* These opcodes should not get here */391392printf ("Found a node with an unassigned AML opcode\n");393FlPrintFile (ASL_FILE_STDERR,394"Found a node with an unassigned AML opcode\n");395return;396397case AML_INT_RESERVEDFIELD_OP:398399/* Special opcodes for within a field definition */400401Aml.Opcode = AML_FIELD_OFFSET_OP;402break;403404case AML_INT_ACCESSFIELD_OP:405406Aml.Opcode = AML_FIELD_ACCESS_OP;407break;408409case AML_INT_CONNECTION_OP:410411Aml.Opcode = AML_FIELD_CONNECTION_OP;412break;413414default:415416Aml.Opcode = Op->Asl.AmlOpcode;417break;418}419420421switch (Aml.Opcode)422{423case AML_PACKAGE_LENGTH:424425/* Value is the length to be encoded (Used in field definitions) */426427PkgLen.Len = (UINT32) Op->Asl.Value.Integer;428break;429430default:431432/* Check for two-byte opcode */433434if (Aml.Opcode > 0x00FF)435{436/* Write the high byte first */437438CgLocalWriteAmlData (Op, &Aml.OpcodeBytes[1], 1);439}440441CgLocalWriteAmlData (Op, &Aml.OpcodeBytes[0], 1);442443/* Subtreelength doesn't include length of package length bytes */444445PkgLen.Len = Op->Asl.AmlSubtreeLength + Op->Asl.AmlPkgLenBytes;446break;447}448449/* Does this opcode have an associated "PackageLength" field? */450451if (Op->Asl.CompileFlags & OP_AML_PACKAGE)452{453if (Op->Asl.AmlPkgLenBytes == 1)454{455/* Simplest case -- no bytes to follow, just write the count */456457CgLocalWriteAmlData (Op, &PkgLen.LenBytes[0], 1);458}459else if (Op->Asl.AmlPkgLenBytes != 0)460{461/*462* Encode the "bytes to follow" in the first byte, top two bits.463* The low-order nybble of the length is in the bottom 4 bits464*/465PkgLenFirstByte = (UINT8)466(((UINT32) (Op->Asl.AmlPkgLenBytes - 1) << 6) |467(PkgLen.LenBytes[0] & 0x0F));468469CgLocalWriteAmlData (Op, &PkgLenFirstByte, 1);470471/*472* Shift the length over by the 4 bits we just stuffed473* in the first byte474*/475PkgLen.Len >>= 4;476477/*478* Now we can write the remaining bytes -479* either 1, 2, or 3 bytes480*/481for (i = 0; i < (UINT32) (Op->Asl.AmlPkgLenBytes - 1); i++)482{483CgLocalWriteAmlData (Op, &PkgLen.LenBytes[i], 1);484}485}486}487488switch (Aml.Opcode)489{490case AML_BYTE_OP:491492CgLocalWriteAmlData (Op, &Op->Asl.Value.Integer, 1);493break;494495case AML_WORD_OP:496497CgLocalWriteAmlData (Op, &Op->Asl.Value.Integer, 2);498break;499500case AML_DWORD_OP:501502CgLocalWriteAmlData (Op, &Op->Asl.Value.Integer, 4);503break;504505case AML_QWORD_OP:506507CgLocalWriteAmlData (Op, &Op->Asl.Value.Integer, 8);508break;509510case AML_STRING_OP:511512CgLocalWriteAmlData (Op, Op->Asl.Value.String, Op->Asl.AmlLength);513break;514515default:516517/* All data opcodes must appear above */518519break;520}521}522523524/*******************************************************************************525*526* FUNCTION: CgWriteTableHeader527*528* PARAMETERS: Op - The DEFINITIONBLOCK node529*530* RETURN: None531*532* DESCRIPTION: Write a table header corresponding to the DEFINITIONBLOCK533*534* NOTE: Input strings should be validated before this function is invoked.535*536******************************************************************************/537538static void539CgWriteTableHeader (540ACPI_PARSE_OBJECT *Op)541{542ACPI_PARSE_OBJECT *Child;543UINT32 CommentLength;544ACPI_COMMENT_NODE *Current;545546547memset (&AslGbl_TableHeader, 0, sizeof (ACPI_TABLE_HEADER));548549/* AML filename */550551Child = Op->Asl.Child;552553/* Signature */554555Child = Child->Asl.Next;556557/*558* For ASL-/ASL+ converter: replace the table signature with559* "XXXX" and save the original table signature. This results in an AML560* file with the signature "XXXX". The converter should remove this AML561* file. In the event where this AML file does not get deleted, the562* "XXXX" table signature prevents this AML file from running on the AML563* interpreter.564*/565if (AcpiGbl_CaptureComments)566{567ACPI_COPY_NAMESEG (AcpiGbl_TableSig, Child->Asl.Value.String);568Child->Asl.Value.String = ACPI_SIG_XXXX;569}570571ACPI_COPY_NAMESEG (AslGbl_TableHeader.Signature, Child->Asl.Value.String);572573/* Revision */574575Child = Child->Asl.Next;576AslGbl_TableHeader.Revision = (UINT8) Child->Asl.Value.Integer;577578/* Command-line Revision override */579580if (AslGbl_RevisionOverride)581{582AslGbl_TableHeader.Revision = AslGbl_RevisionOverride;583}584585/* OEMID */586587Child = Child->Asl.Next;588memcpy (AslGbl_TableHeader.OemId, Child->Asl.Value.String,589strlen (Child->Asl.Value.String));590591/* OEM TableID */592593Child = Child->Asl.Next;594memcpy (AslGbl_TableHeader.OemTableId, Child->Asl.Value.String,595strlen (Child->Asl.Value.String));596597/* OEM Revision */598599Child = Child->Asl.Next;600AslGbl_TableHeader.OemRevision = (UINT32) Child->Asl.Value.Integer;601602/* Compiler ID */603604ACPI_COPY_NAMESEG (AslGbl_TableHeader.AslCompilerId, ASL_CREATOR_ID);605606/* Compiler version */607608AslGbl_TableHeader.AslCompilerRevision = ACPI_CA_VERSION;609610/* Table length. Checksum zero for now, will rewrite later */611612AslGbl_TableHeader.Length = sizeof (ACPI_TABLE_HEADER) +613Op->Asl.AmlSubtreeLength;614615/* Calculate the comment lengths for this definition block parseOp */616617if (AcpiGbl_CaptureComments)618{619CvDbgPrint ("Calculating comment lengths for %s in write header\n",620Op->Asl.ParseOpName);621622/*623* Take the filename without extensions, add 3 for the new extension624* and another 3 for the a908 bytecode and null terminator.625*/626AslGbl_TableHeader.Length += strrchr (AslGbl_ParseTreeRoot->Asl.Filename, '.')627- AslGbl_ParseTreeRoot->Asl.Filename + 1 + 3 + 3;628629Op->Asl.AmlSubtreeLength +=630strlen (AslGbl_ParseTreeRoot->Asl.Filename) + 3;631632CvDbgPrint (" Length: %u\n",633(UINT32) strlen (AslGbl_ParseTreeRoot->Asl.Filename) + 3);634635if (Op->Asl.CommentList)636{637Current = Op->Asl.CommentList;638while (Current)639{640CommentLength = strlen (Current->Comment)+3;641CvDbgPrint ("Length of standard comment): %d\n", CommentLength);642CvDbgPrint (" Comment string: %s\n\n", Current->Comment);643AslGbl_TableHeader.Length += CommentLength;644Op->Asl.AmlSubtreeLength += CommentLength;645Current = Current->Next;646CvDbgPrint (" Length: %u\n", CommentLength);647}648}649if (Op->Asl.CloseBraceComment)650{651CommentLength = strlen (Op->Asl.CloseBraceComment)+3;652CvDbgPrint ("Length of inline comment +3: %d\n", CommentLength);653CvDbgPrint (" Comment string: %s\n\n", Op->Asl.CloseBraceComment);654AslGbl_TableHeader.Length += CommentLength;655Op->Asl.AmlSubtreeLength += CommentLength;656CvDbgPrint (" Length: %u\n", CommentLength);657}658}659660AslGbl_TableHeader.Checksum = 0;661Op->Asl.FinalAmlOffset = ftell (AslGbl_Files[ASL_FILE_AML_OUTPUT].Handle);662663/* Write entire header and clear the table header global */664665CgLocalWriteAmlData (Op, &AslGbl_TableHeader, sizeof (ACPI_TABLE_HEADER));666memset (&AslGbl_TableHeader, 0, sizeof (ACPI_TABLE_HEADER));667}668669670/*******************************************************************************671*672* FUNCTION: CgUpdateCdatHeader673*674* PARAMETERS: Op - Op for the Definition Block675*676* RETURN: None.677*678* DESCRIPTION: Complete the ACPI table by calculating the checksum and679* re-writing the header for the input definition block680*681******************************************************************************/682683static void684CgUpdateCdatHeader (685ACPI_PARSE_OBJECT *Op)686{687signed char Sum;688UINT32 i;689UINT32 Length;690UINT8 FileByte;691UINT8 Checksum;692693694/* Calculate the checksum over the entire definition block */695696Sum = 0;697Length = sizeof (ACPI_TABLE_CDAT) + Op->Asl.AmlSubtreeLength;698FlSeekFile (ASL_FILE_AML_OUTPUT, Op->Asl.FinalAmlOffset);699700for (i = 0; i < Length; i++)701{702if (FlReadFile (ASL_FILE_AML_OUTPUT, &FileByte, 1) != AE_OK)703{704AslError (ASL_ERROR, ASL_MSG_COMPILER_INTERNAL, NULL,705"Table length is greater than size of the input file");706return;707}708709Sum = (signed char) (Sum + FileByte);710}711712Checksum = (UINT8) (0 - Sum);713714DbgPrint (ASL_DEBUG_OUTPUT, "Computed checksum = %X\n", Checksum);715716/* Re-write the checksum byte */717718FlSeekFile (ASL_FILE_AML_OUTPUT, Op->Asl.FinalAmlOffset +719ACPI_CDAT_OFFSET (Checksum));720721FlWriteFile (ASL_FILE_AML_OUTPUT, &Checksum, 1);722723/*724* Seek to the end of the file. This is done to support multiple file725* compilation. Doing this simplifies other parts of the codebase because726* it eliminates the need to seek for a different starting place.727*/728FlSeekFile (ASL_FILE_AML_OUTPUT, Op->Asl.FinalAmlOffset + Length);729}730731/*******************************************************************************732*733* FUNCTION: CgUpdateHeader734*735* PARAMETERS: Op - Op for the Definition Block736*737* RETURN: None.738*739* DESCRIPTION: Complete the ACPI table by calculating the checksum and740* re-writing the header for the input definition block741*742******************************************************************************/743744static void745CgUpdateHeader (746ACPI_PARSE_OBJECT *Op)747{748signed char Sum;749UINT32 i;750UINT32 Length;751UINT8 FileByte;752UINT8 Checksum;753754755/* Calculate the checksum over the entire definition block */756757Sum = 0;758Length = sizeof (ACPI_TABLE_HEADER) + Op->Asl.AmlSubtreeLength;759FlSeekFile (ASL_FILE_AML_OUTPUT, Op->Asl.FinalAmlOffset);760761for (i = 0; i < Length; i++)762{763if (FlReadFile (ASL_FILE_AML_OUTPUT, &FileByte, 1) != AE_OK)764{765AslError (ASL_ERROR, ASL_MSG_COMPILER_INTERNAL, NULL,766"Table length is greater than size of the input file");767return;768}769770Sum = (signed char) (Sum + FileByte);771}772773Checksum = (UINT8) (0 - Sum);774775/* Re-write the checksum byte */776777FlSeekFile (ASL_FILE_AML_OUTPUT, Op->Asl.FinalAmlOffset +778ACPI_OFFSET (ACPI_TABLE_HEADER, Checksum));779780FlWriteFile (ASL_FILE_AML_OUTPUT, &Checksum, 1);781782/*783* Seek to the end of the file. This is done to support multiple file784* compilation. Doing this simplifies other parts of the codebase because785* it eliminates the need to seek for a different starting place.786*/787FlSeekFile (ASL_FILE_AML_OUTPUT, Op->Asl.FinalAmlOffset + Length);788}789790791/*******************************************************************************792*793* FUNCTION: CgWriteNode794*795* PARAMETERS: Op - Parse node to write.796*797* RETURN: None.798*799* DESCRIPTION: Write the AML that corresponds to a parse node.800*801******************************************************************************/802803static void804CgWriteNode (805ACPI_PARSE_OBJECT *Op)806{807ASL_RESOURCE_NODE *Rnode;808809810/* Write all comments here. */811812if (AcpiGbl_CaptureComments)813{814CgWriteAmlComment(Op);815}816817/* Always check for DEFAULT_ARG and other "Noop" nodes */818/* TBD: this may not be the best place for this check */819820if ((Op->Asl.ParseOpcode == PARSEOP_DEFAULT_ARG) ||821(Op->Asl.ParseOpcode == PARSEOP_INCLUDE) ||822(Op->Asl.ParseOpcode == PARSEOP_INCLUDE_END))823{824return;825}826827Op->Asl.FinalAmlLength = 0;828829switch (Op->Asl.AmlOpcode)830{831case AML_RAW_DATA_BYTE:832case AML_RAW_DATA_WORD:833case AML_RAW_DATA_DWORD:834case AML_RAW_DATA_QWORD:835836CgLocalWriteAmlData (Op, &Op->Asl.Value.Integer, Op->Asl.AmlLength);837return;838839840case AML_RAW_DATA_BUFFER:841842CgLocalWriteAmlData (Op, Op->Asl.Value.Buffer, Op->Asl.AmlLength);843return;844845846case AML_RAW_DATA_CHAIN:847848Rnode = ACPI_CAST_PTR (ASL_RESOURCE_NODE, Op->Asl.Value.Buffer);849while (Rnode)850{851CgLocalWriteAmlData (Op, Rnode->Buffer, Rnode->BufferLength);852Rnode = Rnode->Next;853}854return;855856default:857858/* Internal data opcodes must all appear above */859860break;861}862863switch (Op->Asl.ParseOpcode)864{865case PARSEOP_DEFAULT_ARG:866867break;868869case PARSEOP_DEFINITION_BLOCK:870871CgWriteTableHeader (Op);872if (AcpiGbl_CaptureComments)873{874CgWriteAmlDefBlockComment (Op);875}876break;877878case PARSEOP_NAMESEG:879case PARSEOP_NAMESTRING:880case PARSEOP_METHODCALL:881882CgLocalWriteAmlData (Op, Op->Asl.Value.String, Op->Asl.AmlLength);883break;884885default:886887CgWriteAmlOpcode (Op);888break;889}890}891892893