asllisting.c revision 193529
1118611Snjl 2118611Snjl/****************************************************************************** 3118611Snjl * 4118611Snjl * Module Name: asllisting - Listing file generation 5118611Snjl * 6118611Snjl *****************************************************************************/ 7118611Snjl 8118611Snjl/****************************************************************************** 9118611Snjl * 10118611Snjl * 1. Copyright Notice 11118611Snjl * 12193529Sjkim * Some or all of this work - Copyright (c) 1999 - 2009, Intel Corp. 13118611Snjl * All rights reserved. 14118611Snjl * 15118611Snjl * 2. License 16118611Snjl * 17118611Snjl * 2.1. This is your license from Intel Corp. under its intellectual property 18118611Snjl * rights. You may have additional license terms from the party that provided 19118611Snjl * you this software, covering your right to use that party's intellectual 20118611Snjl * property rights. 21118611Snjl * 22118611Snjl * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a 23118611Snjl * copy of the source code appearing in this file ("Covered Code") an 24118611Snjl * irrevocable, perpetual, worldwide license under Intel's copyrights in the 25118611Snjl * base code distributed originally by Intel ("Original Intel Code") to copy, 26118611Snjl * make derivatives, distribute, use and display any portion of the Covered 27118611Snjl * Code in any form, with the right to sublicense such rights; and 28118611Snjl * 29118611Snjl * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent 30118611Snjl * license (with the right to sublicense), under only those claims of Intel 31118611Snjl * patents that are infringed by the Original Intel Code, to make, use, sell, 32118611Snjl * offer to sell, and import the Covered Code and derivative works thereof 33118611Snjl * solely to the minimum extent necessary to exercise the above copyright 34118611Snjl * license, and in no event shall the patent license extend to any additions 35118611Snjl * to or modifications of the Original Intel Code. No other license or right 36118611Snjl * is granted directly or by implication, estoppel or otherwise; 37118611Snjl * 38118611Snjl * The above copyright and patent license is granted only if the following 39118611Snjl * conditions are met: 40118611Snjl * 41118611Snjl * 3. Conditions 42118611Snjl * 43118611Snjl * 3.1. Redistribution of Source with Rights to Further Distribute Source. 44118611Snjl * Redistribution of source code of any substantial portion of the Covered 45118611Snjl * Code or modification with rights to further distribute source must include 46118611Snjl * the above Copyright Notice, the above License, this list of Conditions, 47118611Snjl * and the following Disclaimer and Export Compliance provision. In addition, 48118611Snjl * Licensee must cause all Covered Code to which Licensee contributes to 49118611Snjl * contain a file documenting the changes Licensee made to create that Covered 50118611Snjl * Code and the date of any change. Licensee must include in that file the 51118611Snjl * documentation of any changes made by any predecessor Licensee. Licensee 52118611Snjl * must include a prominent statement that the modification is derived, 53118611Snjl * directly or indirectly, from Original Intel Code. 54118611Snjl * 55118611Snjl * 3.2. Redistribution of Source with no Rights to Further Distribute Source. 56118611Snjl * Redistribution of source code of any substantial portion of the Covered 57118611Snjl * Code or modification without rights to further distribute source must 58118611Snjl * include the following Disclaimer and Export Compliance provision in the 59118611Snjl * documentation and/or other materials provided with distribution. In 60118611Snjl * addition, Licensee may not authorize further sublicense of source of any 61118611Snjl * portion of the Covered Code, and must include terms to the effect that the 62118611Snjl * license from Licensee to its licensee is limited to the intellectual 63118611Snjl * property embodied in the software Licensee provides to its licensee, and 64118611Snjl * not to intellectual property embodied in modifications its licensee may 65118611Snjl * make. 66118611Snjl * 67118611Snjl * 3.3. Redistribution of Executable. Redistribution in executable form of any 68118611Snjl * substantial portion of the Covered Code or modification must reproduce the 69118611Snjl * above Copyright Notice, and the following Disclaimer and Export Compliance 70118611Snjl * provision in the documentation and/or other materials provided with the 71118611Snjl * distribution. 72118611Snjl * 73118611Snjl * 3.4. Intel retains all right, title, and interest in and to the Original 74118611Snjl * Intel Code. 75118611Snjl * 76118611Snjl * 3.5. Neither the name Intel nor any other trademark owned or controlled by 77118611Snjl * Intel shall be used in advertising or otherwise to promote the sale, use or 78118611Snjl * other dealings in products derived from or relating to the Covered Code 79118611Snjl * without prior written authorization from Intel. 80118611Snjl * 81118611Snjl * 4. Disclaimer and Export Compliance 82118611Snjl * 83118611Snjl * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED 84118611Snjl * HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE 85118611Snjl * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE, 86118611Snjl * INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY 87118611Snjl * UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY 88118611Snjl * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A 89118611Snjl * PARTICULAR PURPOSE. 90118611Snjl * 91118611Snjl * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES 92118611Snjl * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR 93118611Snjl * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT, 94118611Snjl * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY 95118611Snjl * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL 96118611Snjl * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS 97118611Snjl * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY 98118611Snjl * LIMITED REMEDY. 99118611Snjl * 100118611Snjl * 4.3. Licensee shall not export, either directly or indirectly, any of this 101118611Snjl * software or system incorporating such software without first obtaining any 102118611Snjl * required license or other approval from the U. S. Department of Commerce or 103118611Snjl * any other agency or department of the United States Government. In the 104118611Snjl * event Licensee exports any such software from the United States or 105118611Snjl * re-exports any such software from a foreign destination, Licensee shall 106118611Snjl * ensure that the distribution and export/re-export of the software is in 107118611Snjl * compliance with all laws, regulations, orders, or other restrictions of the 108118611Snjl * U.S. Export Administration Regulations. Licensee agrees that neither it nor 109118611Snjl * any of its subsidiaries will export/re-export any technical data, process, 110118611Snjl * software, or service, directly or indirectly, to any country for which the 111118611Snjl * United States government or any agency thereof requires an export license, 112118611Snjl * other governmental approval, or letter of assurance, without first obtaining 113118611Snjl * such license, approval or letter. 114118611Snjl * 115118611Snjl *****************************************************************************/ 116118611Snjl 117118611Snjl 118151937Sjkim#include <contrib/dev/acpica/compiler/aslcompiler.h> 119118611Snjl#include "aslcompiler.y.h" 120193529Sjkim#include <contrib/dev/acpica/include/amlcode.h> 121193529Sjkim#include <contrib/dev/acpica/include/acparser.h> 122193529Sjkim#include <contrib/dev/acpica/include/acnamesp.h> 123118611Snjl 124118611Snjl#define _COMPONENT ACPI_COMPILER 125118611Snjl ACPI_MODULE_NAME ("aslisting") 126118611Snjl 127151937Sjkim/* Local prototypes */ 128118611Snjl 129151937Sjkimstatic void 130151937SjkimLsDumpAscii ( 131151937Sjkim UINT32 FileId, 132151937Sjkim UINT32 Count, 133151937Sjkim UINT8 *Buffer); 134151937Sjkim 135151937Sjkimstatic void 136151937SjkimLsDumpAsciiInComment ( 137151937Sjkim UINT32 FileId, 138151937Sjkim UINT32 Count, 139151937Sjkim UINT8 *Buffer); 140151937Sjkim 141151937Sjkimstatic ACPI_STATUS 142151937SjkimLsAmlListingWalk ( 143151937Sjkim ACPI_PARSE_OBJECT *Op, 144151937Sjkim UINT32 Level, 145151937Sjkim void *Context); 146151937Sjkim 147151937Sjkimstatic void 148151937SjkimLsGenerateListing ( 149151937Sjkim UINT32 FileId); 150151937Sjkim 151151937Sjkimstatic void 152151937SjkimLsPushNode ( 153151937Sjkim char *Filename); 154151937Sjkim 155151937Sjkimstatic ASL_LISTING_NODE * 156151937SjkimLsPopNode ( 157151937Sjkim void); 158151937Sjkim 159151937Sjkimstatic void 160151937SjkimLsCheckException ( 161151937Sjkim UINT32 LineNumber, 162151937Sjkim UINT32 FileId); 163151937Sjkim 164151937Sjkimstatic void 165151937SjkimLsFlushListingBuffer ( 166151937Sjkim UINT32 FileId); 167151937Sjkim 168151937Sjkimstatic void 169151937SjkimLsWriteListingHexBytes ( 170151937Sjkim UINT8 *Buffer, 171151937Sjkim UINT32 Length, 172151937Sjkim UINT32 FileId); 173151937Sjkim 174151937Sjkimstatic UINT32 175151937SjkimLsWriteOneSourceLine ( 176151937Sjkim UINT32 FileId); 177151937Sjkim 178151937Sjkimstatic void 179151937SjkimLsFinishSourceListing ( 180151937Sjkim UINT32 FileId); 181151937Sjkim 182151937Sjkimstatic void 183151937SjkimLsWriteSourceLines ( 184151937Sjkim UINT32 ToLineNumber, 185151937Sjkim UINT32 ToLogicalLineNumber, 186151937Sjkim UINT32 FileId); 187151937Sjkim 188151937Sjkimstatic void 189151937SjkimLsWriteNodeToListing ( 190151937Sjkim ACPI_PARSE_OBJECT *Op, 191151937Sjkim UINT32 FileId); 192151937Sjkim 193151937Sjkimstatic void 194151937SjkimLsDoHexOutputC ( 195151937Sjkim void); 196151937Sjkim 197151937Sjkimstatic void 198151937SjkimLsDoHexOutputAsm ( 199151937Sjkim void); 200151937Sjkim 201193529SjkimACPI_STATUS 202193529SjkimLsTreeWriteWalk ( 203193529Sjkim ACPI_PARSE_OBJECT *Op, 204193529Sjkim UINT32 Level, 205193529Sjkim void *Context); 206151937Sjkim 207193529Sjkim 208118611Snjl/******************************************************************************* 209118611Snjl * 210167802Sjkim * FUNCTION: LsTreeWriteWalk 211167802Sjkim * 212167802Sjkim * PARAMETERS: ASL_WALK_CALLBACK 213167802Sjkim * 214167802Sjkim * 215167802Sjkim * RETURN: None. 216167802Sjkim * 217167802Sjkim * DESCRIPTION: Dump entire parse tree, for compiler debug only 218167802Sjkim * 219167802Sjkim ******************************************************************************/ 220167802Sjkim 221167802SjkimACPI_STATUS 222167802SjkimLsTreeWriteWalk ( 223167802Sjkim ACPI_PARSE_OBJECT *Op, 224167802Sjkim UINT32 Level, 225167802Sjkim void *Context) 226167802Sjkim{ 227167802Sjkim 228167802Sjkim /* Debug output */ 229167802Sjkim 230167802Sjkim DbgPrint (ASL_TREE_OUTPUT, 231167802Sjkim "%5.5d [%2d]", Op->Asl.LogicalLineNumber, Level); 232167802Sjkim UtPrintFormattedName (Op->Asl.ParseOpcode, Level); 233167802Sjkim 234167802Sjkim 235167802Sjkim DbgPrint (ASL_TREE_OUTPUT, "\n"); 236167802Sjkim return (AE_OK); 237167802Sjkim} 238167802Sjkim 239167802Sjkim 240167802Sjkimvoid 241167802SjkimLsDumpParseTree ( 242167802Sjkim void) 243167802Sjkim{ 244167802Sjkim 245167802Sjkim if (!Gbl_DebugFlag) 246167802Sjkim { 247167802Sjkim return; 248167802Sjkim } 249167802Sjkim 250167802Sjkim DbgPrint (ASL_TREE_OUTPUT, "\nOriginal parse tree from parser:\n\n"); 251167802Sjkim TrWalkParseTree (RootNode, ASL_WALK_VISIT_DOWNWARD, 252167802Sjkim LsTreeWriteWalk, NULL, NULL); 253167802Sjkim} 254167802Sjkim 255167802Sjkim 256167802Sjkim/******************************************************************************* 257167802Sjkim * 258118611Snjl * FUNCTION: LsDumpAscii 259118611Snjl * 260118611Snjl * PARAMETERS: FileId - ID of current listing file 261118611Snjl * Count - Number of bytes to convert 262118611Snjl * Buffer - Buffer of bytes to convert 263118611Snjl * 264118611Snjl * RETURN: None. 265118611Snjl * 266118611Snjl * DESCRIPTION: Convert hex bytes to ascii 267118611Snjl * 268118611Snjl ******************************************************************************/ 269118611Snjl 270151937Sjkimstatic void 271118611SnjlLsDumpAscii ( 272118611Snjl UINT32 FileId, 273118611Snjl UINT32 Count, 274118611Snjl UINT8 *Buffer) 275118611Snjl{ 276118611Snjl UINT8 BufChar; 277118611Snjl UINT32 i; 278118611Snjl 279118611Snjl 280118611Snjl FlPrintFile (FileId, " \""); 281118611Snjl for (i = 0; i < Count; i++) 282118611Snjl { 283118611Snjl BufChar = Buffer[i]; 284118611Snjl if (isprint (BufChar)) 285118611Snjl { 286118611Snjl FlPrintFile (FileId, "%c", BufChar); 287118611Snjl } 288118611Snjl else 289118611Snjl { 290118611Snjl /* Not a printable character, just put out a dot */ 291118611Snjl 292118611Snjl FlPrintFile (FileId, "."); 293118611Snjl } 294118611Snjl } 295118611Snjl FlPrintFile (FileId, "\""); 296118611Snjl} 297118611Snjl 298118611Snjl 299118611Snjl/******************************************************************************* 300118611Snjl * 301118611Snjl * FUNCTION: LsDumpAsciiInComment 302118611Snjl * 303118611Snjl * PARAMETERS: FileId - ID of current listing file 304118611Snjl * Count - Number of bytes to convert 305118611Snjl * Buffer - Buffer of bytes to convert 306118611Snjl * 307118611Snjl * RETURN: None. 308118611Snjl * 309118611Snjl * DESCRIPTION: Convert hex bytes to ascii 310118611Snjl * 311118611Snjl ******************************************************************************/ 312118611Snjl 313151937Sjkimstatic void 314118611SnjlLsDumpAsciiInComment ( 315118611Snjl UINT32 FileId, 316118611Snjl UINT32 Count, 317118611Snjl UINT8 *Buffer) 318118611Snjl{ 319118611Snjl UINT8 BufChar = 0; 320118611Snjl UINT8 LastChar; 321118611Snjl UINT32 i; 322118611Snjl 323118611Snjl 324118611Snjl FlPrintFile (FileId, " \""); 325118611Snjl for (i = 0; i < Count; i++) 326118611Snjl { 327118611Snjl LastChar = BufChar; 328118611Snjl BufChar = Buffer[i]; 329118611Snjl 330118611Snjl if (isprint (BufChar)) 331118611Snjl { 332118611Snjl /* Handle embedded C comment sequences */ 333118611Snjl 334118611Snjl if (((LastChar == '*') && (BufChar == '/')) || 335118611Snjl ((LastChar == '/') && (BufChar == '*'))) 336118611Snjl { 337118611Snjl /* Insert a space to break the sequence */ 338118611Snjl 339118611Snjl FlPrintFile (FileId, ".", BufChar); 340118611Snjl } 341118611Snjl 342118611Snjl FlPrintFile (FileId, "%c", BufChar); 343118611Snjl } 344118611Snjl else 345118611Snjl { 346118611Snjl /* Not a printable character, just put out a dot */ 347118611Snjl 348118611Snjl FlPrintFile (FileId, "."); 349118611Snjl } 350118611Snjl } 351118611Snjl FlPrintFile (FileId, "\""); 352118611Snjl} 353118611Snjl 354118611Snjl 355118611Snjl/******************************************************************************* 356118611Snjl * 357118611Snjl * FUNCTION: LsAmlListingWalk 358118611Snjl * 359118611Snjl * PARAMETERS: ASL_WALK_CALLBACK 360118611Snjl * 361118611Snjl * RETURN: Status 362118611Snjl * 363118611Snjl * DESCRIPTION: Process one node during a listing file generation. 364118611Snjl * 365118611Snjl ******************************************************************************/ 366118611Snjl 367151937Sjkimstatic ACPI_STATUS 368118611SnjlLsAmlListingWalk ( 369118611Snjl ACPI_PARSE_OBJECT *Op, 370118611Snjl UINT32 Level, 371118611Snjl void *Context) 372118611Snjl{ 373118611Snjl UINT8 FileByte; 374118611Snjl UINT32 i; 375167802Sjkim UINT32 FileId = (UINT32) ACPI_TO_INTEGER (Context); 376118611Snjl 377118611Snjl 378118611Snjl LsWriteNodeToListing (Op, FileId); 379118611Snjl 380167802Sjkim if (Op->Asl.CompileFlags & NODE_IS_RESOURCE_DATA) 381167802Sjkim { 382167802Sjkim /* Buffer is a resource template, don't dump the data all at once */ 383167802Sjkim 384167802Sjkim return (AE_OK); 385167802Sjkim } 386167802Sjkim 387118611Snjl /* Write the hex bytes to the listing file(s) (if requested) */ 388118611Snjl 389118611Snjl for (i = 0; i < Op->Asl.FinalAmlLength; i++) 390118611Snjl { 391118611Snjl if (ACPI_FAILURE (FlReadFile (ASL_FILE_AML_OUTPUT, &FileByte, 1))) 392118611Snjl { 393118611Snjl FlFileError (ASL_FILE_AML_OUTPUT, ASL_MSG_READ); 394118611Snjl AslAbort (); 395118611Snjl } 396118611Snjl LsWriteListingHexBytes (&FileByte, 1, FileId); 397118611Snjl } 398118611Snjl 399118611Snjl return (AE_OK); 400118611Snjl} 401118611Snjl 402118611Snjl 403118611Snjl/******************************************************************************* 404118611Snjl * 405118611Snjl * FUNCTION: LsGenerateListing 406118611Snjl * 407118611Snjl * PARAMETERS: FileId - ID of listing file 408118611Snjl * 409118611Snjl * RETURN: None 410118611Snjl * 411118611Snjl * DESCRIPTION: Generate a listing file. This can be one of the several types 412118611Snjl * of "listings" supported. 413118611Snjl * 414118611Snjl ******************************************************************************/ 415118611Snjl 416151937Sjkimstatic void 417118611SnjlLsGenerateListing ( 418118611Snjl UINT32 FileId) 419118611Snjl{ 420118611Snjl 421118611Snjl /* Start at the beginning of both the source and AML files */ 422118611Snjl 423118611Snjl FlSeekFile (ASL_FILE_SOURCE_OUTPUT, 0); 424118611Snjl FlSeekFile (ASL_FILE_AML_OUTPUT, 0); 425118611Snjl Gbl_SourceLine = 0; 426118611Snjl Gbl_CurrentHexColumn = 0; 427118611Snjl LsPushNode (Gbl_Files[ASL_FILE_INPUT].Filename); 428118611Snjl 429118611Snjl /* Process all parse nodes */ 430118611Snjl 431118611Snjl TrWalkParseTree (RootNode, ASL_WALK_VISIT_DOWNWARD, LsAmlListingWalk, 432118611Snjl NULL, (void *) ACPI_TO_POINTER (FileId)); 433118611Snjl 434118611Snjl /* Final processing */ 435118611Snjl 436118611Snjl LsFinishSourceListing (FileId); 437118611Snjl} 438118611Snjl 439118611Snjl 440118611Snjl/******************************************************************************* 441118611Snjl * 442118611Snjl * FUNCTION: LsDoListings 443118611Snjl * 444118611Snjl * PARAMETERS: None. 445118611Snjl * 446118611Snjl * RETURN: None 447118611Snjl * 448118611Snjl * DESCRIPTION: Generate all requested listing files. 449118611Snjl * 450118611Snjl ******************************************************************************/ 451118611Snjl 452118611Snjlvoid 453151937SjkimLsDoListings ( 454151937Sjkim void) 455118611Snjl{ 456118611Snjl 457118611Snjl if (Gbl_C_OutputFlag) 458118611Snjl { 459118611Snjl LsGenerateListing (ASL_FILE_C_SOURCE_OUTPUT); 460118611Snjl } 461118611Snjl 462118611Snjl if (Gbl_ListingFlag) 463118611Snjl { 464118611Snjl LsGenerateListing (ASL_FILE_LISTING_OUTPUT); 465118611Snjl } 466118611Snjl 467118611Snjl if (Gbl_AsmOutputFlag) 468118611Snjl { 469118611Snjl LsGenerateListing (ASL_FILE_ASM_SOURCE_OUTPUT); 470118611Snjl } 471118611Snjl 472118611Snjl if (Gbl_C_IncludeOutputFlag) 473118611Snjl { 474118611Snjl LsGenerateListing (ASL_FILE_C_INCLUDE_OUTPUT); 475118611Snjl } 476118611Snjl 477118611Snjl if (Gbl_AsmIncludeOutputFlag) 478118611Snjl { 479118611Snjl LsGenerateListing (ASL_FILE_ASM_INCLUDE_OUTPUT); 480118611Snjl } 481118611Snjl} 482118611Snjl 483118611Snjl 484118611Snjl/******************************************************************************* 485118611Snjl * 486118611Snjl * FUNCTION: LsPushNode 487118611Snjl * 488118611Snjl * PARAMETERS: Filename - Pointer to the include filename 489118611Snjl * 490118611Snjl * RETURN: None 491118611Snjl * 492118611Snjl * DESCRIPTION: Push a listing node on the listing/include file stack. This 493118611Snjl * stack enables tracking of include files (infinitely nested) 494118611Snjl * and resumption of the listing of the parent file when the 495118611Snjl * include file is finished. 496118611Snjl * 497118611Snjl ******************************************************************************/ 498118611Snjl 499151937Sjkimstatic void 500118611SnjlLsPushNode ( 501118611Snjl char *Filename) 502118611Snjl{ 503118611Snjl ASL_LISTING_NODE *Lnode; 504118611Snjl 505118611Snjl 506118611Snjl /* Create a new node */ 507118611Snjl 508118611Snjl Lnode = UtLocalCalloc (sizeof (ASL_LISTING_NODE)); 509118611Snjl 510118611Snjl /* Initialize */ 511118611Snjl 512118611Snjl Lnode->Filename = Filename; 513118611Snjl Lnode->LineNumber = 0; 514118611Snjl 515118611Snjl /* Link (push) */ 516118611Snjl 517118611Snjl Lnode->Next = Gbl_ListingNode; 518118611Snjl Gbl_ListingNode = Lnode; 519118611Snjl} 520118611Snjl 521118611Snjl 522118611Snjl/******************************************************************************* 523118611Snjl * 524118611Snjl * FUNCTION: LsPopNode 525118611Snjl * 526118611Snjl * PARAMETERS: None 527118611Snjl * 528118611Snjl * RETURN: List head after current head is popped off 529118611Snjl * 530118611Snjl * DESCRIPTION: Pop the current head of the list, free it, and return the 531118611Snjl * next node on the stack (the new current node). 532118611Snjl * 533118611Snjl ******************************************************************************/ 534118611Snjl 535151937Sjkimstatic ASL_LISTING_NODE * 536151937SjkimLsPopNode ( 537151937Sjkim void) 538118611Snjl{ 539118611Snjl ASL_LISTING_NODE *Lnode; 540118611Snjl 541118611Snjl 542118611Snjl /* Just grab the node at the head of the list */ 543118611Snjl 544118611Snjl Lnode = Gbl_ListingNode; 545118611Snjl if ((!Lnode) || 546118611Snjl (!Lnode->Next)) 547118611Snjl { 548151937Sjkim AslError (ASL_ERROR, ASL_MSG_COMPILER_INTERNAL, NULL, 549151937Sjkim "Could not pop empty listing stack"); 550118611Snjl return Gbl_ListingNode; 551118611Snjl } 552118611Snjl 553118611Snjl Gbl_ListingNode = Lnode->Next; 554167802Sjkim ACPI_FREE (Lnode); 555118611Snjl 556118611Snjl /* New "Current" node is the new head */ 557118611Snjl 558118611Snjl return (Gbl_ListingNode); 559118611Snjl} 560118611Snjl 561118611Snjl 562118611Snjl/******************************************************************************* 563118611Snjl * 564118611Snjl * FUNCTION: LsCheckException 565118611Snjl * 566118611Snjl * PARAMETERS: LineNumber - Current logical (cumulative) line # 567118611Snjl * FileId - ID of output listing file 568118611Snjl * 569118611Snjl * RETURN: None 570118611Snjl * 571118611Snjl * DESCRIPTION: Check if there is an exception for this line, and if there is, 572118611Snjl * put it in the listing immediately. Handles multiple errors 573118611Snjl * per line. Gbl_NextError points to the next error in the 574118611Snjl * sorted (by line #) list of compile errors/warnings. 575118611Snjl * 576118611Snjl ******************************************************************************/ 577118611Snjl 578151937Sjkimstatic void 579118611SnjlLsCheckException ( 580118611Snjl UINT32 LineNumber, 581118611Snjl UINT32 FileId) 582118611Snjl{ 583118611Snjl 584118611Snjl if ((!Gbl_NextError) || 585118611Snjl (LineNumber < Gbl_NextError->LogicalLineNumber )) 586118611Snjl { 587118611Snjl return; 588118611Snjl } 589118611Snjl 590118611Snjl /* Handle multiple errors per line */ 591118611Snjl 592118611Snjl if (FileId == ASL_FILE_LISTING_OUTPUT) 593118611Snjl { 594118611Snjl while (Gbl_NextError && 595118611Snjl (LineNumber >= Gbl_NextError->LogicalLineNumber)) 596118611Snjl { 597118611Snjl AePrintException (FileId, Gbl_NextError, "\n[****iasl****]\n"); 598118611Snjl 599118611Snjl Gbl_NextError = Gbl_NextError->Next; 600118611Snjl } 601118611Snjl 602118611Snjl FlPrintFile (FileId, "\n"); 603118611Snjl } 604118611Snjl} 605118611Snjl 606118611Snjl 607118611Snjl/******************************************************************************* 608118611Snjl * 609118611Snjl * FUNCTION: LsFlushListingBuffer 610118611Snjl * 611118611Snjl * PARAMETERS: FileId - ID of the listing file 612118611Snjl * 613118611Snjl * RETURN: None 614118611Snjl * 615118611Snjl * DESCRIPTION: Flush out the current contents of the 16-byte hex AML code 616118611Snjl * buffer. Usually called at the termination of a single line 617118611Snjl * of source code or when the buffer is full. 618118611Snjl * 619118611Snjl ******************************************************************************/ 620118611Snjl 621151937Sjkimstatic void 622118611SnjlLsFlushListingBuffer ( 623118611Snjl UINT32 FileId) 624118611Snjl{ 625118611Snjl UINT32 i; 626118611Snjl 627118611Snjl 628118611Snjl if (Gbl_CurrentHexColumn == 0) 629118611Snjl { 630118611Snjl return; 631118611Snjl } 632118611Snjl 633118611Snjl /* Write the hex bytes */ 634118611Snjl 635118611Snjl switch (FileId) 636118611Snjl { 637118611Snjl case ASL_FILE_LISTING_OUTPUT: 638118611Snjl 639118611Snjl for (i = 0; i < Gbl_CurrentHexColumn; i++) 640118611Snjl { 641118611Snjl FlPrintFile (FileId, "%2.2X ", Gbl_AmlBuffer[i]); 642118611Snjl } 643118611Snjl 644118611Snjl for (i = 0; i < ((HEX_LISTING_LINE_SIZE - Gbl_CurrentHexColumn) * 3); i++) 645118611Snjl { 646118611Snjl FlWriteFile (FileId, ".", 1); 647118611Snjl } 648118611Snjl 649118611Snjl /* Write the ASCII character associated with each of the bytes */ 650118611Snjl 651118611Snjl LsDumpAscii (FileId, Gbl_CurrentHexColumn, Gbl_AmlBuffer); 652118611Snjl break; 653118611Snjl 654118611Snjl 655118611Snjl case ASL_FILE_ASM_SOURCE_OUTPUT: 656118611Snjl 657118611Snjl for (i = 0; i < Gbl_CurrentHexColumn; i++) 658118611Snjl { 659118611Snjl if (i > 0) 660118611Snjl { 661118611Snjl FlPrintFile (FileId, ","); 662118611Snjl } 663118611Snjl FlPrintFile (FileId, "0%2.2Xh", Gbl_AmlBuffer[i]); 664118611Snjl } 665118611Snjl 666118611Snjl for (i = 0; i < ((HEX_LISTING_LINE_SIZE - Gbl_CurrentHexColumn) * 5); i++) 667118611Snjl { 668118611Snjl FlWriteFile (FileId, " ", 1); 669118611Snjl } 670118611Snjl 671151937Sjkim FlPrintFile (FileId, " ;%8.8X", 672151937Sjkim Gbl_CurrentAmlOffset - HEX_LISTING_LINE_SIZE); 673118611Snjl 674118611Snjl /* Write the ASCII character associated with each of the bytes */ 675118611Snjl 676118611Snjl LsDumpAscii (FileId, Gbl_CurrentHexColumn, Gbl_AmlBuffer); 677118611Snjl break; 678118611Snjl 679118611Snjl 680118611Snjl case ASL_FILE_C_SOURCE_OUTPUT: 681118611Snjl 682118611Snjl for (i = 0; i < Gbl_CurrentHexColumn; i++) 683118611Snjl { 684118611Snjl FlPrintFile (FileId, "0x%2.2X,", Gbl_AmlBuffer[i]); 685118611Snjl } 686118611Snjl 687118611Snjl for (i = 0; i < ((HEX_LISTING_LINE_SIZE - Gbl_CurrentHexColumn) * 5); i++) 688118611Snjl { 689118611Snjl FlWriteFile (FileId, " ", 1); 690118611Snjl } 691118611Snjl 692151937Sjkim FlPrintFile (FileId, " /* %8.8X", 693151937Sjkim Gbl_CurrentAmlOffset - HEX_LISTING_LINE_SIZE); 694118611Snjl 695118611Snjl /* Write the ASCII character associated with each of the bytes */ 696118611Snjl 697118611Snjl LsDumpAsciiInComment (FileId, Gbl_CurrentHexColumn, Gbl_AmlBuffer); 698118611Snjl FlPrintFile (FileId, " */"); 699118611Snjl break; 700118611Snjl 701118611Snjl default: 702118611Snjl /* No other types supported */ 703118611Snjl return; 704118611Snjl } 705118611Snjl 706118611Snjl FlPrintFile (FileId, "\n"); 707118611Snjl 708118611Snjl Gbl_CurrentHexColumn = 0; 709118611Snjl Gbl_HexBytesWereWritten = TRUE; 710118611Snjl} 711118611Snjl 712118611Snjl 713118611Snjl/******************************************************************************* 714118611Snjl * 715118611Snjl * FUNCTION: LsWriteListingHexBytes 716118611Snjl * 717118611Snjl * PARAMETERS: Buffer - AML code buffer 718118611Snjl * Length - Number of AML bytes to write 719118611Snjl * FileId - ID of current listing file. 720118611Snjl * 721118611Snjl * RETURN: None 722118611Snjl * 723118611Snjl * DESCRIPTION: Write the contents of the AML buffer to the listing file via 724118611Snjl * the listing buffer. The listing buffer is flushed every 16 725118611Snjl * AML bytes. 726118611Snjl * 727118611Snjl ******************************************************************************/ 728118611Snjl 729151937Sjkimstatic void 730118611SnjlLsWriteListingHexBytes ( 731118611Snjl UINT8 *Buffer, 732118611Snjl UINT32 Length, 733118611Snjl UINT32 FileId) 734118611Snjl{ 735118611Snjl UINT32 i; 736118611Snjl 737118611Snjl 738118611Snjl /* Transfer all requested bytes */ 739118611Snjl 740118611Snjl for (i = 0; i < Length; i++) 741118611Snjl { 742118611Snjl /* Print line header when buffer is empty */ 743118611Snjl 744118611Snjl if (Gbl_CurrentHexColumn == 0) 745118611Snjl { 746118611Snjl if (Gbl_HasIncludeFiles) 747118611Snjl { 748118611Snjl FlPrintFile (FileId, "%*s", 10, " "); 749118611Snjl } 750118611Snjl 751118611Snjl switch (FileId) 752118611Snjl { 753118611Snjl case ASL_FILE_LISTING_OUTPUT: 754118611Snjl 755118611Snjl FlPrintFile (FileId, "%8.8X....", Gbl_CurrentAmlOffset); 756118611Snjl break; 757118611Snjl 758118611Snjl case ASL_FILE_ASM_SOURCE_OUTPUT: 759118611Snjl 760118611Snjl FlPrintFile (FileId, " db "); 761118611Snjl break; 762118611Snjl 763118611Snjl case ASL_FILE_C_SOURCE_OUTPUT: 764118611Snjl 765118611Snjl FlPrintFile (FileId, " "); 766118611Snjl break; 767118611Snjl 768118611Snjl default: 769118611Snjl /* No other types supported */ 770118611Snjl return; 771118611Snjl } 772118611Snjl } 773118611Snjl 774118611Snjl /* Transfer AML byte and update counts */ 775118611Snjl 776118611Snjl Gbl_AmlBuffer[Gbl_CurrentHexColumn] = Buffer[i]; 777118611Snjl 778118611Snjl Gbl_CurrentHexColumn++; 779118611Snjl Gbl_CurrentAmlOffset++; 780118611Snjl 781118611Snjl /* Flush buffer when it is full */ 782118611Snjl 783118611Snjl if (Gbl_CurrentHexColumn >= HEX_LISTING_LINE_SIZE) 784118611Snjl { 785118611Snjl LsFlushListingBuffer (FileId); 786118611Snjl } 787118611Snjl } 788118611Snjl} 789118611Snjl 790118611Snjl 791118611Snjl/******************************************************************************* 792118611Snjl * 793118611Snjl * FUNCTION: LsWriteOneSourceLine 794118611Snjl * 795118611Snjl * PARAMETERS: FileID - ID of current listing file 796118611Snjl * 797118611Snjl * RETURN: FALSE on EOF (input source file), TRUE otherwise 798118611Snjl * 799118611Snjl * DESCRIPTION: Read one line from the input source file and echo it to the 800118611Snjl * listing file, prefixed with the line number, and if the source 801118611Snjl * file contains include files, prefixed with the current filename 802118611Snjl * 803118611Snjl ******************************************************************************/ 804118611Snjl 805151937Sjkimstatic UINT32 806118611SnjlLsWriteOneSourceLine ( 807118611Snjl UINT32 FileId) 808118611Snjl{ 809118611Snjl UINT8 FileByte; 810118611Snjl 811118611Snjl 812118611Snjl Gbl_SourceLine++; 813118611Snjl Gbl_ListingNode->LineNumber++; 814118611Snjl 815118611Snjl if (FileId == ASL_FILE_C_SOURCE_OUTPUT) 816118611Snjl { 817118611Snjl FlPrintFile (FileId, " *"); 818118611Snjl } 819118611Snjl if (FileId == ASL_FILE_ASM_SOURCE_OUTPUT) 820118611Snjl { 821118611Snjl FlPrintFile (FileId, "; "); 822118611Snjl } 823118611Snjl 824118611Snjl if (Gbl_HasIncludeFiles) 825118611Snjl { 826118611Snjl /* 827118611Snjl * This file contains "include" statements, print the current 828118611Snjl * filename and line number within the current file 829118611Snjl */ 830118611Snjl FlPrintFile (FileId, "%12s %5d....", 831118611Snjl Gbl_ListingNode->Filename, Gbl_ListingNode->LineNumber); 832118611Snjl } 833118611Snjl else 834118611Snjl { 835118611Snjl /* No include files, just print the line number */ 836118611Snjl 837118611Snjl FlPrintFile (FileId, "%8d....", Gbl_SourceLine); 838118611Snjl } 839118611Snjl 840118611Snjl /* Read one line (up to a newline or EOF) */ 841118611Snjl 842118611Snjl while (FlReadFile (ASL_FILE_SOURCE_OUTPUT, &FileByte, 1) == AE_OK) 843118611Snjl { 844118611Snjl if (FileId == ASL_FILE_C_SOURCE_OUTPUT) 845118611Snjl { 846118611Snjl if (FileByte == '/') 847118611Snjl { 848118611Snjl FileByte = '*'; 849118611Snjl } 850118611Snjl } 851118611Snjl 852118611Snjl FlWriteFile (FileId, &FileByte, 1); 853118611Snjl if (FileByte == '\n') 854118611Snjl { 855118611Snjl /* 856118611Snjl * Check if an error occurred on this source line during the compile. 857118611Snjl * If so, we print the error message after the source line. 858118611Snjl */ 859118611Snjl LsCheckException (Gbl_SourceLine, FileId); 860118611Snjl return (1); 861118611Snjl } 862118611Snjl } 863118611Snjl 864118611Snjl /* EOF on the input file was reached */ 865118611Snjl 866118611Snjl return (0); 867118611Snjl} 868118611Snjl 869118611Snjl 870118611Snjl/******************************************************************************* 871118611Snjl * 872118611Snjl * FUNCTION: LsFinishSourceListing 873118611Snjl * 874118611Snjl * PARAMETERS: FileId - ID of current listing file. 875118611Snjl * 876118611Snjl * RETURN: None 877118611Snjl * 878118611Snjl * DESCRIPTION: Cleanup routine for the listing file. Flush the hex AML 879118611Snjl * listing buffer, and flush out any remaining lines in the 880118611Snjl * source input file. 881118611Snjl * 882118611Snjl ******************************************************************************/ 883118611Snjl 884151937Sjkimstatic void 885118611SnjlLsFinishSourceListing ( 886118611Snjl UINT32 FileId) 887118611Snjl{ 888118611Snjl 889118611Snjl if ((FileId == ASL_FILE_ASM_INCLUDE_OUTPUT) || 890118611Snjl (FileId == ASL_FILE_C_INCLUDE_OUTPUT)) 891118611Snjl { 892118611Snjl return; 893118611Snjl } 894118611Snjl 895118611Snjl LsFlushListingBuffer (FileId); 896118611Snjl Gbl_CurrentAmlOffset = 0; 897118611Snjl 898118611Snjl /* Flush any remaining text in the source file */ 899118611Snjl 900118611Snjl if (FileId == ASL_FILE_C_SOURCE_OUTPUT) 901118611Snjl { 902118611Snjl FlPrintFile (FileId, " /*\n"); 903118611Snjl } 904118611Snjl 905118611Snjl while (LsWriteOneSourceLine (FileId)) 906118611Snjl { ; } 907118611Snjl 908118611Snjl if (FileId == ASL_FILE_C_SOURCE_OUTPUT) 909118611Snjl { 910118611Snjl FlPrintFile (FileId, "\n */\n };\n"); 911118611Snjl } 912118611Snjl 913118611Snjl FlPrintFile (FileId, "\n"); 914118611Snjl 915118611Snjl if (FileId == ASL_FILE_LISTING_OUTPUT) 916118611Snjl { 917118611Snjl /* Print a summary of the compile exceptions */ 918118611Snjl 919118611Snjl FlPrintFile (FileId, "\n\nSummary of errors and warnings\n\n"); 920118611Snjl AePrintErrorLog (FileId); 921118611Snjl FlPrintFile (FileId, "\n\n"); 922118611Snjl UtDisplaySummary (FileId); 923118611Snjl FlPrintFile (FileId, "\n\n"); 924118611Snjl } 925118611Snjl} 926118611Snjl 927118611Snjl 928118611Snjl/******************************************************************************* 929118611Snjl * 930118611Snjl * FUNCTION: LsWriteSourceLines 931118611Snjl * 932118611Snjl * PARAMETERS: ToLineNumber - 933118611Snjl * ToLogicalLineNumber - Write up to this source line number 934118611Snjl * FileId - ID of current listing file 935118611Snjl * 936118611Snjl * RETURN: None 937118611Snjl * 938118611Snjl * DESCRIPTION: Read then write source lines to the listing file until we have 939118611Snjl * reached the specified logical (cumulative) line number. This 940118611Snjl * automatically echos out comment blocks and other non-AML 941118611Snjl * generating text until we get to the actual AML-generating line 942118611Snjl * of ASL code specified by the logical line number. 943118611Snjl * 944118611Snjl ******************************************************************************/ 945118611Snjl 946151937Sjkimstatic void 947118611SnjlLsWriteSourceLines ( 948118611Snjl UINT32 ToLineNumber, 949118611Snjl UINT32 ToLogicalLineNumber, 950118611Snjl UINT32 FileId) 951118611Snjl{ 952118611Snjl 953118611Snjl if ((FileId == ASL_FILE_ASM_INCLUDE_OUTPUT) || 954118611Snjl (FileId == ASL_FILE_C_INCLUDE_OUTPUT)) 955118611Snjl { 956118611Snjl return; 957118611Snjl } 958118611Snjl 959118611Snjl Gbl_CurrentLine = ToLogicalLineNumber; 960118611Snjl 961118611Snjl /* Flush any hex bytes remaining from the last opcode */ 962118611Snjl 963118611Snjl LsFlushListingBuffer (FileId); 964118611Snjl 965151937Sjkim /* Read lines and write them as long as we are not caught up */ 966151937Sjkim 967118611Snjl if (Gbl_SourceLine < Gbl_CurrentLine) 968118611Snjl { 969118611Snjl /* 970118611Snjl * If we just completed writing some AML hex bytes, output a linefeed 971118611Snjl * to add some whitespace for readability. 972118611Snjl */ 973118611Snjl if (Gbl_HexBytesWereWritten) 974118611Snjl { 975118611Snjl FlPrintFile (FileId, "\n"); 976118611Snjl Gbl_HexBytesWereWritten = FALSE; 977118611Snjl } 978118611Snjl 979118611Snjl if (FileId == ASL_FILE_C_SOURCE_OUTPUT) 980118611Snjl { 981118611Snjl FlPrintFile (FileId, " /*\n"); 982118611Snjl } 983118611Snjl 984151937Sjkim /* Write one line at a time until we have reached the target line # */ 985151937Sjkim 986118611Snjl while ((Gbl_SourceLine < Gbl_CurrentLine) && 987118611Snjl LsWriteOneSourceLine (FileId)) 988118611Snjl { ; } 989118611Snjl 990118611Snjl if (FileId == ASL_FILE_C_SOURCE_OUTPUT) 991118611Snjl { 992118611Snjl FlPrintFile (FileId, " */"); 993118611Snjl } 994118611Snjl FlPrintFile (FileId, "\n"); 995118611Snjl } 996118611Snjl} 997118611Snjl 998118611Snjl 999118611Snjl/******************************************************************************* 1000118611Snjl * 1001118611Snjl * FUNCTION: LsWriteNodeToListing 1002118611Snjl * 1003118611Snjl * PARAMETERS: Op - Parse node to write to the listing file. 1004118611Snjl * FileId - ID of current listing file 1005118611Snjl * 1006118611Snjl * RETURN: None. 1007118611Snjl * 1008118611Snjl * DESCRIPTION: Write "a node" to the listing file. This means to 1009118611Snjl * 1) Write out all of the source text associated with the node 1010118611Snjl * 2) Write out all of the AML bytes associated with the node 1011118611Snjl * 3) Write any compiler exceptions associated with the node 1012118611Snjl * 1013118611Snjl ******************************************************************************/ 1014118611Snjl 1015151937Sjkimstatic void 1016118611SnjlLsWriteNodeToListing ( 1017118611Snjl ACPI_PARSE_OBJECT *Op, 1018118611Snjl UINT32 FileId) 1019118611Snjl{ 1020118611Snjl const ACPI_OPCODE_INFO *OpInfo; 1021118611Snjl UINT32 OpClass; 1022118611Snjl char *Pathname; 1023118611Snjl UINT32 Length; 1024118611Snjl UINT32 i; 1025118611Snjl 1026118611Snjl 1027118611Snjl OpInfo = AcpiPsGetOpcodeInfo (Op->Asl.AmlOpcode); 1028118611Snjl OpClass = OpInfo->Class; 1029118611Snjl 1030151937Sjkim /* TBD: clean this up with a single flag that says: 1031151937Sjkim * I start a named output block 1032151937Sjkim */ 1033118611Snjl if (FileId == ASL_FILE_C_SOURCE_OUTPUT) 1034118611Snjl { 1035118611Snjl switch (Op->Asl.ParseOpcode) 1036118611Snjl { 1037118611Snjl case PARSEOP_DEFINITIONBLOCK: 1038118611Snjl case PARSEOP_METHODCALL: 1039118611Snjl case PARSEOP_INCLUDE: 1040118611Snjl case PARSEOP_INCLUDE_END: 1041118611Snjl case PARSEOP_DEFAULT_ARG: 1042118611Snjl 1043118611Snjl break; 1044118611Snjl 1045118611Snjl default: 1046118611Snjl switch (OpClass) 1047118611Snjl { 1048118611Snjl case AML_CLASS_NAMED_OBJECT: 1049118611Snjl switch (Op->Asl.AmlOpcode) 1050118611Snjl { 1051118611Snjl case AML_SCOPE_OP: 1052118611Snjl case AML_ALIAS_OP: 1053118611Snjl break; 1054118611Snjl 1055118611Snjl default: 1056118611Snjl if (Op->Asl.ExternalName) 1057118611Snjl { 1058118611Snjl LsFlushListingBuffer (FileId); 1059118611Snjl FlPrintFile (FileId, " };\n"); 1060118611Snjl } 1061118611Snjl break; 1062118611Snjl } 1063118611Snjl break; 1064118611Snjl 1065118611Snjl default: 1066118611Snjl /* Don't care about other objects */ 1067118611Snjl break; 1068118611Snjl } 1069118611Snjl break; 1070118611Snjl } 1071118611Snjl } 1072118611Snjl 1073118611Snjl /* These cases do not have a corresponding AML opcode */ 1074118611Snjl 1075118611Snjl switch (Op->Asl.ParseOpcode) 1076118611Snjl { 1077118611Snjl case PARSEOP_DEFINITIONBLOCK: 1078118611Snjl 1079118611Snjl LsWriteSourceLines (Op->Asl.EndLine, Op->Asl.EndLogicalLine, FileId); 1080118611Snjl 1081118611Snjl /* Use the table Signature and TableId to build a unique name */ 1082118611Snjl 1083118611Snjl if (FileId == ASL_FILE_ASM_SOURCE_OUTPUT) 1084118611Snjl { 1085151937Sjkim FlPrintFile (FileId, 1086151937Sjkim "%s_%s_Header \\\n", 1087118611Snjl Gbl_TableSignature, Gbl_TableId); 1088118611Snjl } 1089118611Snjl if (FileId == ASL_FILE_C_SOURCE_OUTPUT) 1090118611Snjl { 1091151937Sjkim FlPrintFile (FileId, 1092151937Sjkim " unsigned char %s_%s_Header [] =\n {\n", 1093118611Snjl Gbl_TableSignature, Gbl_TableId); 1094118611Snjl } 1095118611Snjl if (FileId == ASL_FILE_ASM_INCLUDE_OUTPUT) 1096118611Snjl { 1097151937Sjkim FlPrintFile (FileId, 1098151937Sjkim "extrn %s_%s_Header : byte\n", 1099118611Snjl Gbl_TableSignature, Gbl_TableId); 1100118611Snjl } 1101118611Snjl if (FileId == ASL_FILE_C_INCLUDE_OUTPUT) 1102118611Snjl { 1103151937Sjkim FlPrintFile (FileId, 1104151937Sjkim "extern unsigned char %s_%s_Header [];\n", 1105118611Snjl Gbl_TableSignature, Gbl_TableId); 1106118611Snjl } 1107118611Snjl return; 1108118611Snjl 1109118611Snjl 1110118611Snjl case PARSEOP_METHODCALL: 1111118611Snjl 1112151937Sjkim LsWriteSourceLines (Op->Asl.LineNumber, Op->Asl.LogicalLineNumber, 1113151937Sjkim FileId); 1114118611Snjl return; 1115118611Snjl 1116118611Snjl 1117118611Snjl case PARSEOP_INCLUDE: 1118118611Snjl 1119151937Sjkim /* Flush everything up to and including the include source line */ 1120118611Snjl 1121151937Sjkim LsWriteSourceLines (Op->Asl.LineNumber, Op->Asl.LogicalLineNumber, 1122151937Sjkim FileId); 1123151937Sjkim 1124151937Sjkim /* Create a new listing node and push it */ 1125151937Sjkim 1126118611Snjl LsPushNode (Op->Asl.Child->Asl.Value.String); 1127118611Snjl return; 1128118611Snjl 1129118611Snjl 1130118611Snjl case PARSEOP_INCLUDE_END: 1131118611Snjl 1132151937Sjkim /* Flush out the rest of the include file */ 1133118611Snjl 1134151937Sjkim LsWriteSourceLines (Op->Asl.LineNumber, Op->Asl.LogicalLineNumber, 1135151937Sjkim FileId); 1136151937Sjkim 1137151937Sjkim /* Pop off this listing node and go back to the parent file */ 1138151937Sjkim 1139151937Sjkim (void) LsPopNode (); 1140118611Snjl return; 1141118611Snjl 1142118611Snjl 1143118611Snjl case PARSEOP_DEFAULT_ARG: 1144167802Sjkim 1145167802Sjkim if (Op->Asl.CompileFlags & NODE_IS_RESOURCE_DESC) 1146167802Sjkim { 1147167802Sjkim LsWriteSourceLines (Op->Asl.LineNumber, Op->Asl.EndLogicalLine, 1148167802Sjkim FileId); 1149167802Sjkim } 1150118611Snjl return; 1151118611Snjl 1152118611Snjl 1153118611Snjl default: 1154118611Snjl /* All other opcodes have an AML opcode */ 1155118611Snjl break; 1156118611Snjl } 1157118611Snjl 1158118611Snjl /* 1159118611Snjl * Otherwise, we look at the AML opcode because we can 1160118611Snjl * switch on the opcode type, getting an entire class 1161118611Snjl * at once 1162118611Snjl */ 1163118611Snjl switch (OpClass) 1164118611Snjl { 1165118611Snjl case AML_CLASS_ARGUMENT: /* argument type only */ 1166118611Snjl case AML_CLASS_INTERNAL: 1167118611Snjl 1168118611Snjl break; 1169118611Snjl 1170118611Snjl 1171118611Snjl case AML_CLASS_NAMED_OBJECT: 1172118611Snjl 1173118611Snjl switch (Op->Asl.AmlOpcode) 1174118611Snjl { 1175118611Snjl case AML_FIELD_OP: 1176118611Snjl case AML_INDEX_FIELD_OP: 1177118611Snjl case AML_BANK_FIELD_OP: 1178118611Snjl 1179151937Sjkim /* 1180151937Sjkim * For fields, we want to dump all the AML after the 1181151937Sjkim * entire definition 1182151937Sjkim */ 1183151937Sjkim LsWriteSourceLines (Op->Asl.EndLine, Op->Asl.EndLogicalLine, 1184151937Sjkim FileId); 1185118611Snjl break; 1186118611Snjl 1187167802Sjkim case AML_NAME_OP: 1188167802Sjkim 1189167802Sjkim if (Op->Asl.CompileFlags & NODE_IS_RESOURCE_DESC) 1190167802Sjkim { 1191167802Sjkim LsWriteSourceLines (Op->Asl.LineNumber, Op->Asl.LogicalLineNumber, 1192167802Sjkim FileId); 1193167802Sjkim } 1194167802Sjkim else 1195167802Sjkim { 1196167802Sjkim /* 1197167802Sjkim * For fields, we want to dump all the AML after the 1198167802Sjkim * entire definition 1199167802Sjkim */ 1200167802Sjkim LsWriteSourceLines (Op->Asl.EndLine, Op->Asl.EndLogicalLine, 1201167802Sjkim FileId); 1202167802Sjkim } 1203167802Sjkim break; 1204167802Sjkim 1205118611Snjl default: 1206151937Sjkim LsWriteSourceLines (Op->Asl.LineNumber, Op->Asl.LogicalLineNumber, 1207151937Sjkim FileId); 1208118611Snjl break; 1209118611Snjl } 1210118611Snjl 1211118611Snjl switch (Op->Asl.AmlOpcode) 1212118611Snjl { 1213118611Snjl case AML_SCOPE_OP: 1214118611Snjl case AML_ALIAS_OP: 1215118611Snjl 1216118611Snjl /* These opcodes do not declare a new object, ignore them */ 1217118611Snjl 1218118611Snjl break; 1219118611Snjl 1220118611Snjl default: 1221118611Snjl 1222118611Snjl /* All other named object opcodes come here */ 1223118611Snjl 1224118611Snjl switch (FileId) 1225118611Snjl { 1226118611Snjl case ASL_FILE_ASM_SOURCE_OUTPUT: 1227118611Snjl case ASL_FILE_C_SOURCE_OUTPUT: 1228118611Snjl case ASL_FILE_ASM_INCLUDE_OUTPUT: 1229118611Snjl case ASL_FILE_C_INCLUDE_OUTPUT: 1230118611Snjl 1231118611Snjl /* 1232118611Snjl * For named objects, we will create a valid symbol so that the 1233118611Snjl * AML code can be referenced from C or ASM 1234118611Snjl */ 1235118611Snjl if (Op->Asl.ExternalName) 1236118611Snjl { 1237118611Snjl /* Get the full pathname associated with this node */ 1238118611Snjl 1239118611Snjl Pathname = AcpiNsGetExternalPathname (Op->Asl.Node); 1240118611Snjl Length = strlen (Pathname); 1241118611Snjl if (Length >= 4) 1242118611Snjl { 1243118611Snjl /* Convert all dots in the path to underscores */ 1244118611Snjl 1245118611Snjl for (i = 0; i < Length; i++) 1246118611Snjl { 1247118611Snjl if (Pathname[i] == '.') 1248118611Snjl { 1249118611Snjl Pathname[i] = '_'; 1250118611Snjl } 1251118611Snjl } 1252118611Snjl 1253118611Snjl /* Create the appropriate symbol in the output file */ 1254118611Snjl 1255118611Snjl if (FileId == ASL_FILE_ASM_SOURCE_OUTPUT) 1256118611Snjl { 1257151937Sjkim FlPrintFile (FileId, 1258151937Sjkim "%s_%s_%s \\\n", 1259118611Snjl Gbl_TableSignature, Gbl_TableId, &Pathname[1]); 1260118611Snjl } 1261118611Snjl if (FileId == ASL_FILE_C_SOURCE_OUTPUT) 1262118611Snjl { 1263151937Sjkim FlPrintFile (FileId, 1264151937Sjkim " unsigned char %s_%s_%s [] =\n {\n", 1265118611Snjl Gbl_TableSignature, Gbl_TableId, &Pathname[1]); 1266118611Snjl } 1267118611Snjl if (FileId == ASL_FILE_ASM_INCLUDE_OUTPUT) 1268118611Snjl { 1269151937Sjkim FlPrintFile (FileId, 1270151937Sjkim "extrn %s_%s_%s : byte\n", 1271118611Snjl Gbl_TableSignature, Gbl_TableId, &Pathname[1]); 1272118611Snjl } 1273118611Snjl if (FileId == ASL_FILE_C_INCLUDE_OUTPUT) 1274118611Snjl { 1275151937Sjkim FlPrintFile (FileId, 1276151937Sjkim "extern unsigned char %s_%s_%s [];\n", 1277118611Snjl Gbl_TableSignature, Gbl_TableId, &Pathname[1]); 1278118611Snjl } 1279118611Snjl } 1280167802Sjkim ACPI_FREE (Pathname); 1281118611Snjl } 1282118611Snjl break; 1283118611Snjl 1284118611Snjl default: 1285118611Snjl /* Nothing to do for listing file */ 1286118611Snjl break; 1287118611Snjl } 1288118611Snjl } 1289118611Snjl break; 1290118611Snjl 1291118611Snjl case AML_CLASS_EXECUTE: 1292118611Snjl case AML_CLASS_CREATE: 1293118611Snjl default: 1294118611Snjl 1295167802Sjkim if ((Op->Asl.ParseOpcode == PARSEOP_BUFFER) && 1296167802Sjkim (Op->Asl.CompileFlags & NODE_IS_RESOURCE_DESC)) 1297167802Sjkim { 1298167802Sjkim return; 1299167802Sjkim } 1300167802Sjkim 1301151937Sjkim LsWriteSourceLines (Op->Asl.LineNumber, Op->Asl.LogicalLineNumber, 1302151937Sjkim FileId); 1303118611Snjl break; 1304118611Snjl 1305118611Snjl case AML_CLASS_UNKNOWN: 1306118611Snjl break; 1307118611Snjl } 1308118611Snjl} 1309118611Snjl 1310118611Snjl 1311118611Snjl/******************************************************************************* 1312118611Snjl * 1313118611Snjl * FUNCTION: LsDoHexOutput 1314118611Snjl * 1315118611Snjl * PARAMETERS: None 1316118611Snjl * 1317118611Snjl * RETURN: None. 1318118611Snjl * 1319118611Snjl * DESCRIPTION: Create the hex output file. 1320118611Snjl * 1321118611Snjl ******************************************************************************/ 1322118611Snjl 1323118611Snjlvoid 1324151937SjkimLsDoHexOutput ( 1325151937Sjkim void) 1326118611Snjl{ 1327118611Snjl 1328118611Snjl switch (Gbl_HexOutputFlag) 1329118611Snjl { 1330118611Snjl case HEX_OUTPUT_C: 1331118611Snjl 1332118611Snjl LsDoHexOutputC (); 1333118611Snjl break; 1334118611Snjl 1335118611Snjl case HEX_OUTPUT_ASM: 1336118611Snjl 1337118611Snjl LsDoHexOutputAsm (); 1338118611Snjl break; 1339118611Snjl 1340118611Snjl default: 1341118611Snjl /* No other output types supported */ 1342118611Snjl break; 1343118611Snjl } 1344118611Snjl} 1345118611Snjl 1346118611Snjl 1347118611Snjl/******************************************************************************* 1348118611Snjl * 1349118611Snjl * FUNCTION: LsDoHexOutputC 1350118611Snjl * 1351118611Snjl * PARAMETERS: None 1352118611Snjl * 1353118611Snjl * RETURN: None. 1354118611Snjl * 1355118611Snjl * DESCRIPTION: Create the hex output file. This is the same data as the AML 1356118611Snjl * output file, but formatted into hex/ascii bytes suitable for 1357118611Snjl * inclusion into a C source file. 1358118611Snjl * 1359118611Snjl ******************************************************************************/ 1360118611Snjl 1361151937Sjkimstatic void 1362151937SjkimLsDoHexOutputC ( 1363151937Sjkim void) 1364118611Snjl{ 1365118611Snjl UINT32 j; 1366118611Snjl UINT8 FileByte[HEX_TABLE_LINE_SIZE]; 1367118611Snjl UINT8 Buffer[4]; 1368118611Snjl UINT32 Offset = 0; 1369118611Snjl 1370118611Snjl 1371118611Snjl FlPrintFile (ASL_FILE_HEX_OUTPUT, " * C source code output\n *\n */\n"); 1372151937Sjkim FlPrintFile (ASL_FILE_HEX_OUTPUT, "unsigned char AmlCode[] =\n{\n"); 1373118611Snjl 1374118611Snjl /* Start at the beginning of the AML file */ 1375118611Snjl 1376118611Snjl FlSeekFile (ASL_FILE_AML_OUTPUT, 0); 1377118611Snjl 1378118611Snjl /* Process all AML bytes in the AML file */ 1379118611Snjl 1380118611Snjl j = 0; 1381118611Snjl while (FlReadFile (ASL_FILE_AML_OUTPUT, &FileByte[j], 1) == AE_OK) 1382118611Snjl { 1383118611Snjl if (j == 0) 1384118611Snjl { 1385118611Snjl FlPrintFile (ASL_FILE_HEX_OUTPUT, " "); 1386118611Snjl } 1387118611Snjl 1388151937Sjkim /* Convert each AML byte to hex */ 1389151937Sjkim 1390118611Snjl UtConvertByteToHex (FileByte[j], Buffer); 1391118611Snjl FlWriteFile (ASL_FILE_HEX_OUTPUT, Buffer, 4); 1392118611Snjl FlPrintFile (ASL_FILE_HEX_OUTPUT, ","); 1393118611Snjl 1394118611Snjl /* An occasional linefeed improves readability */ 1395118611Snjl 1396118611Snjl Offset++; 1397118611Snjl j++; 1398118611Snjl 1399118611Snjl if (j >= HEX_TABLE_LINE_SIZE) 1400118611Snjl { 1401118611Snjl /* End of line, emit the ascii dump of the entire line */ 1402118611Snjl 1403151937Sjkim FlPrintFile (ASL_FILE_HEX_OUTPUT, 1404151937Sjkim " /* %8.8X", Offset - HEX_TABLE_LINE_SIZE); 1405118611Snjl 1406118611Snjl /* Write the ASCII character associated with each of the bytes */ 1407118611Snjl 1408151937Sjkim LsDumpAsciiInComment (ASL_FILE_HEX_OUTPUT, 1409151937Sjkim HEX_TABLE_LINE_SIZE, FileByte); 1410118611Snjl FlPrintFile (ASL_FILE_HEX_OUTPUT, " */\n"); 1411118611Snjl 1412118611Snjl /* Start new line */ 1413118611Snjl 1414118611Snjl j = 0; 1415118611Snjl } 1416118611Snjl } 1417118611Snjl 1418118611Snjl FlPrintFile (ASL_FILE_HEX_OUTPUT, "\n};\n"); 1419118611Snjl FlCloseFile (ASL_FILE_HEX_OUTPUT); 1420118611Snjl} 1421118611Snjl 1422118611Snjl 1423118611Snjl/******************************************************************************* 1424118611Snjl * 1425118611Snjl * FUNCTION: LsDoHexOutputAsm 1426118611Snjl * 1427118611Snjl * PARAMETERS: None 1428118611Snjl * 1429118611Snjl * RETURN: None. 1430118611Snjl * 1431118611Snjl * DESCRIPTION: Create the hex output file. This is the same data as the AML 1432118611Snjl * output file, but formatted into hex/ascii bytes suitable for 1433118611Snjl * inclusion into a ASM source file. 1434118611Snjl * 1435118611Snjl ******************************************************************************/ 1436118611Snjl 1437151937Sjkimstatic void 1438118611SnjlLsDoHexOutputAsm ( 1439118611Snjl void) 1440118611Snjl{ 1441118611Snjl UINT32 j; 1442118611Snjl UINT8 FileByte[HEX_TABLE_LINE_SIZE]; 1443118611Snjl UINT8 Buffer[4]; 1444118611Snjl UINT32 Offset = 0; 1445118611Snjl BOOLEAN DoComma = FALSE; 1446118611Snjl 1447118611Snjl 1448118611Snjl FlPrintFile (ASL_FILE_HEX_OUTPUT, "; Assembly code source output\n;\n"); 1449118611Snjl 1450118611Snjl /* Start at the beginning of the AML file */ 1451118611Snjl 1452118611Snjl FlSeekFile (ASL_FILE_AML_OUTPUT, 0); 1453118611Snjl 1454118611Snjl /* Process all AML bytes in the AML file */ 1455118611Snjl 1456118611Snjl j = 0; 1457118611Snjl while (FlReadFile (ASL_FILE_AML_OUTPUT, &FileByte[j], 1) == AE_OK) 1458118611Snjl { 1459118611Snjl if (j == 0) 1460118611Snjl { 1461118611Snjl FlPrintFile (ASL_FILE_HEX_OUTPUT, " db "); 1462118611Snjl } 1463118611Snjl else if (DoComma) 1464118611Snjl { 1465118611Snjl FlPrintFile (ASL_FILE_HEX_OUTPUT, ","); 1466118611Snjl DoComma = FALSE; 1467118611Snjl } 1468118611Snjl 1469151937Sjkim /* Convert each AML byte to hex */ 1470151937Sjkim 1471118611Snjl UtConvertByteToAsmHex (FileByte[j], Buffer); 1472118611Snjl FlWriteFile (ASL_FILE_HEX_OUTPUT, Buffer, 4); 1473118611Snjl 1474118611Snjl /* An occasional linefeed improves readability */ 1475118611Snjl 1476118611Snjl Offset++; 1477118611Snjl j++; 1478118611Snjl if (j >= HEX_TABLE_LINE_SIZE) 1479118611Snjl { 1480151937Sjkim FlPrintFile (ASL_FILE_HEX_OUTPUT, 1481151937Sjkim " ;%8.8X", Offset - HEX_TABLE_LINE_SIZE); 1482118611Snjl 1483118611Snjl /* Write the ASCII character associated with each of the bytes */ 1484118611Snjl 1485118611Snjl LsDumpAscii (ASL_FILE_HEX_OUTPUT, HEX_TABLE_LINE_SIZE, FileByte); 1486118611Snjl FlPrintFile (ASL_FILE_HEX_OUTPUT, "\n"); 1487118611Snjl j = 0; 1488118611Snjl } 1489118611Snjl else 1490118611Snjl { 1491118611Snjl DoComma = TRUE; 1492118611Snjl } 1493118611Snjl } 1494118611Snjl 1495118611Snjl FlPrintFile (ASL_FILE_HEX_OUTPUT, "\n"); 1496118611Snjl FlCloseFile (ASL_FILE_HEX_OUTPUT); 1497118611Snjl} 1498118611Snjl 1499118611Snjl 1500