1249109Sjkim/****************************************************************************** 2249109Sjkim * 3249109Sjkim * Module Name: asllistsup - Listing file support utilities 4249109Sjkim * 5249109Sjkim *****************************************************************************/ 6249109Sjkim 7316303Sjkim/****************************************************************************** 8316303Sjkim * 9316303Sjkim * 1. Copyright Notice 10316303Sjkim * 11316303Sjkim * Some or all of this work - Copyright (c) 1999 - 2017, Intel Corp. 12249109Sjkim * All rights reserved. 13249109Sjkim * 14316303Sjkim * 2. License 15316303Sjkim * 16316303Sjkim * 2.1. This is your license from Intel Corp. under its intellectual property 17316303Sjkim * rights. You may have additional license terms from the party that provided 18316303Sjkim * you this software, covering your right to use that party's intellectual 19316303Sjkim * property rights. 20316303Sjkim * 21316303Sjkim * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a 22316303Sjkim * copy of the source code appearing in this file ("Covered Code") an 23316303Sjkim * irrevocable, perpetual, worldwide license under Intel's copyrights in the 24316303Sjkim * base code distributed originally by Intel ("Original Intel Code") to copy, 25316303Sjkim * make derivatives, distribute, use and display any portion of the Covered 26316303Sjkim * Code in any form, with the right to sublicense such rights; and 27316303Sjkim * 28316303Sjkim * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent 29316303Sjkim * license (with the right to sublicense), under only those claims of Intel 30316303Sjkim * patents that are infringed by the Original Intel Code, to make, use, sell, 31316303Sjkim * offer to sell, and import the Covered Code and derivative works thereof 32316303Sjkim * solely to the minimum extent necessary to exercise the above copyright 33316303Sjkim * license, and in no event shall the patent license extend to any additions 34316303Sjkim * to or modifications of the Original Intel Code. No other license or right 35316303Sjkim * is granted directly or by implication, estoppel or otherwise; 36316303Sjkim * 37316303Sjkim * The above copyright and patent license is granted only if the following 38316303Sjkim * conditions are met: 39316303Sjkim * 40316303Sjkim * 3. Conditions 41316303Sjkim * 42316303Sjkim * 3.1. Redistribution of Source with Rights to Further Distribute Source. 43316303Sjkim * Redistribution of source code of any substantial portion of the Covered 44316303Sjkim * Code or modification with rights to further distribute source must include 45316303Sjkim * the above Copyright Notice, the above License, this list of Conditions, 46316303Sjkim * and the following Disclaimer and Export Compliance provision. In addition, 47316303Sjkim * Licensee must cause all Covered Code to which Licensee contributes to 48316303Sjkim * contain a file documenting the changes Licensee made to create that Covered 49316303Sjkim * Code and the date of any change. Licensee must include in that file the 50316303Sjkim * documentation of any changes made by any predecessor Licensee. Licensee 51316303Sjkim * must include a prominent statement that the modification is derived, 52316303Sjkim * directly or indirectly, from Original Intel Code. 53316303Sjkim * 54316303Sjkim * 3.2. Redistribution of Source with no Rights to Further Distribute Source. 55316303Sjkim * Redistribution of source code of any substantial portion of the Covered 56316303Sjkim * Code or modification without rights to further distribute source must 57316303Sjkim * include the following Disclaimer and Export Compliance provision in the 58316303Sjkim * documentation and/or other materials provided with distribution. In 59316303Sjkim * addition, Licensee may not authorize further sublicense of source of any 60316303Sjkim * portion of the Covered Code, and must include terms to the effect that the 61316303Sjkim * license from Licensee to its licensee is limited to the intellectual 62316303Sjkim * property embodied in the software Licensee provides to its licensee, and 63316303Sjkim * not to intellectual property embodied in modifications its licensee may 64316303Sjkim * make. 65316303Sjkim * 66316303Sjkim * 3.3. Redistribution of Executable. Redistribution in executable form of any 67316303Sjkim * substantial portion of the Covered Code or modification must reproduce the 68316303Sjkim * above Copyright Notice, and the following Disclaimer and Export Compliance 69316303Sjkim * provision in the documentation and/or other materials provided with the 70316303Sjkim * distribution. 71316303Sjkim * 72316303Sjkim * 3.4. Intel retains all right, title, and interest in and to the Original 73316303Sjkim * Intel Code. 74316303Sjkim * 75316303Sjkim * 3.5. Neither the name Intel nor any other trademark owned or controlled by 76316303Sjkim * Intel shall be used in advertising or otherwise to promote the sale, use or 77316303Sjkim * other dealings in products derived from or relating to the Covered Code 78316303Sjkim * without prior written authorization from Intel. 79316303Sjkim * 80316303Sjkim * 4. Disclaimer and Export Compliance 81316303Sjkim * 82316303Sjkim * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED 83316303Sjkim * HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE 84316303Sjkim * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE, 85316303Sjkim * INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY 86316303Sjkim * UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY 87316303Sjkim * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A 88316303Sjkim * PARTICULAR PURPOSE. 89316303Sjkim * 90316303Sjkim * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES 91316303Sjkim * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR 92316303Sjkim * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT, 93316303Sjkim * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY 94316303Sjkim * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL 95316303Sjkim * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS 96316303Sjkim * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY 97316303Sjkim * LIMITED REMEDY. 98316303Sjkim * 99316303Sjkim * 4.3. Licensee shall not export, either directly or indirectly, any of this 100316303Sjkim * software or system incorporating such software without first obtaining any 101316303Sjkim * required license or other approval from the U. S. Department of Commerce or 102316303Sjkim * any other agency or department of the United States Government. In the 103316303Sjkim * event Licensee exports any such software from the United States or 104316303Sjkim * re-exports any such software from a foreign destination, Licensee shall 105316303Sjkim * ensure that the distribution and export/re-export of the software is in 106316303Sjkim * compliance with all laws, regulations, orders, or other restrictions of the 107316303Sjkim * U.S. Export Administration Regulations. Licensee agrees that neither it nor 108316303Sjkim * any of its subsidiaries will export/re-export any technical data, process, 109316303Sjkim * software, or service, directly or indirectly, to any country for which the 110316303Sjkim * United States government or any agency thereof requires an export license, 111316303Sjkim * other governmental approval, or letter of assurance, without first obtaining 112316303Sjkim * such license, approval or letter. 113316303Sjkim * 114316303Sjkim ***************************************************************************** 115316303Sjkim * 116316303Sjkim * Alternatively, you may choose to be licensed under the terms of the 117316303Sjkim * following license: 118316303Sjkim * 119249109Sjkim * Redistribution and use in source and binary forms, with or without 120249109Sjkim * modification, are permitted provided that the following conditions 121249109Sjkim * are met: 122249109Sjkim * 1. Redistributions of source code must retain the above copyright 123249109Sjkim * notice, this list of conditions, and the following disclaimer, 124249109Sjkim * without modification. 125249109Sjkim * 2. Redistributions in binary form must reproduce at minimum a disclaimer 126249109Sjkim * substantially similar to the "NO WARRANTY" disclaimer below 127249109Sjkim * ("Disclaimer") and any redistribution must be conditioned upon 128249109Sjkim * including a substantially similar Disclaimer requirement for further 129249109Sjkim * binary redistribution. 130249109Sjkim * 3. Neither the names of the above-listed copyright holders nor the names 131249109Sjkim * of any contributors may be used to endorse or promote products derived 132249109Sjkim * from this software without specific prior written permission. 133249109Sjkim * 134316303Sjkim * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 135316303Sjkim * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 136316303Sjkim * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 137316303Sjkim * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 138316303Sjkim * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 139316303Sjkim * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 140316303Sjkim * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 141316303Sjkim * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 142316303Sjkim * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 143316303Sjkim * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 144316303Sjkim * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 145316303Sjkim * 146316303Sjkim * Alternatively, you may choose to be licensed under the terms of the 147249109Sjkim * GNU General Public License ("GPL") version 2 as published by the Free 148249109Sjkim * Software Foundation. 149249109Sjkim * 150316303Sjkim *****************************************************************************/ 151249109Sjkim 152249112Sjkim#include <contrib/dev/acpica/compiler/aslcompiler.h> 153249109Sjkim#include "aslcompiler.y.h" 154249109Sjkim 155249109Sjkim 156249109Sjkim#define _COMPONENT ACPI_COMPILER 157249109Sjkim ACPI_MODULE_NAME ("aslistsup") 158249109Sjkim 159249109Sjkim 160249109Sjkim/******************************************************************************* 161249109Sjkim * 162249109Sjkim * FUNCTION: LsDumpAscii 163249109Sjkim * 164249109Sjkim * PARAMETERS: FileId - ID of current listing file 165249109Sjkim * Count - Number of bytes to convert 166249109Sjkim * Buffer - Buffer of bytes to convert 167249109Sjkim * 168249109Sjkim * RETURN: None 169249109Sjkim * 170249109Sjkim * DESCRIPTION: Convert hex bytes to ascii 171249109Sjkim * 172249109Sjkim ******************************************************************************/ 173249109Sjkim 174249109Sjkimvoid 175249109SjkimLsDumpAscii ( 176249109Sjkim UINT32 FileId, 177249109Sjkim UINT32 Count, 178249109Sjkim UINT8 *Buffer) 179249109Sjkim{ 180249109Sjkim UINT8 BufChar; 181249109Sjkim UINT32 i; 182249109Sjkim 183249109Sjkim 184249109Sjkim FlPrintFile (FileId, " \""); 185249109Sjkim for (i = 0; i < Count; i++) 186249109Sjkim { 187249109Sjkim BufChar = Buffer[i]; 188249109Sjkim if (isprint (BufChar)) 189249109Sjkim { 190249109Sjkim FlPrintFile (FileId, "%c", BufChar); 191249109Sjkim } 192249109Sjkim else 193249109Sjkim { 194249109Sjkim /* Not a printable character, just put out a dot */ 195249109Sjkim 196249109Sjkim FlPrintFile (FileId, "."); 197249109Sjkim } 198249109Sjkim } 199298714Sjkim 200249109Sjkim FlPrintFile (FileId, "\""); 201249109Sjkim} 202249109Sjkim 203249109Sjkim 204249109Sjkim/******************************************************************************* 205249109Sjkim * 206249109Sjkim * FUNCTION: LsDumpAsciiInComment 207249109Sjkim * 208249109Sjkim * PARAMETERS: FileId - ID of current listing file 209249109Sjkim * Count - Number of bytes to convert 210249109Sjkim * Buffer - Buffer of bytes to convert 211249109Sjkim * 212249109Sjkim * RETURN: None 213249109Sjkim * 214249109Sjkim * DESCRIPTION: Convert hex bytes to ascii 215249109Sjkim * 216249109Sjkim ******************************************************************************/ 217249109Sjkim 218249109Sjkimvoid 219249109SjkimLsDumpAsciiInComment ( 220249109Sjkim UINT32 FileId, 221249109Sjkim UINT32 Count, 222249109Sjkim UINT8 *Buffer) 223249109Sjkim{ 224249109Sjkim UINT8 BufChar = 0; 225249109Sjkim UINT8 LastChar; 226249109Sjkim UINT32 i; 227249109Sjkim 228249109Sjkim 229249109Sjkim FlPrintFile (FileId, " \""); 230249109Sjkim for (i = 0; i < Count; i++) 231249109Sjkim { 232249109Sjkim LastChar = BufChar; 233249109Sjkim BufChar = Buffer[i]; 234249109Sjkim 235249109Sjkim if (isprint (BufChar)) 236249109Sjkim { 237249109Sjkim /* Handle embedded C comment sequences */ 238249109Sjkim 239249109Sjkim if (((LastChar == '*') && (BufChar == '/')) || 240249109Sjkim ((LastChar == '/') && (BufChar == '*'))) 241249109Sjkim { 242249109Sjkim /* Insert a space to break the sequence */ 243249109Sjkim 244249109Sjkim FlPrintFile (FileId, ".", BufChar); 245249109Sjkim } 246249109Sjkim 247249109Sjkim FlPrintFile (FileId, "%c", BufChar); 248249109Sjkim } 249249109Sjkim else 250249109Sjkim { 251249109Sjkim /* Not a printable character, just put out a dot */ 252249109Sjkim 253249109Sjkim FlPrintFile (FileId, "."); 254249109Sjkim } 255249109Sjkim } 256249109Sjkim 257249109Sjkim FlPrintFile (FileId, "\""); 258249109Sjkim} 259249109Sjkim 260249109Sjkim 261249109Sjkim/******************************************************************************* 262249109Sjkim * 263249109Sjkim * FUNCTION: LsCheckException 264249109Sjkim * 265249109Sjkim * PARAMETERS: LineNumber - Current logical (cumulative) line # 266249109Sjkim * FileId - ID of output listing file 267249109Sjkim * 268249109Sjkim * RETURN: None 269249109Sjkim * 270249109Sjkim * DESCRIPTION: Check if there is an exception for this line, and if there is, 271249109Sjkim * put it in the listing immediately. Handles multiple errors 272249109Sjkim * per line. Gbl_NextError points to the next error in the 273249109Sjkim * sorted (by line #) list of compile errors/warnings. 274249109Sjkim * 275249109Sjkim ******************************************************************************/ 276249109Sjkim 277249109Sjkimvoid 278249109SjkimLsCheckException ( 279249109Sjkim UINT32 LineNumber, 280249109Sjkim UINT32 FileId) 281249109Sjkim{ 282249109Sjkim 283249109Sjkim if ((!Gbl_NextError) || 284249109Sjkim (LineNumber < Gbl_NextError->LogicalLineNumber )) 285249109Sjkim { 286249109Sjkim return; 287249109Sjkim } 288249109Sjkim 289249109Sjkim /* Handle multiple errors per line */ 290249109Sjkim 291249109Sjkim if (FileId == ASL_FILE_LISTING_OUTPUT) 292249109Sjkim { 293249109Sjkim while (Gbl_NextError && 294249109Sjkim (LineNumber >= Gbl_NextError->LogicalLineNumber)) 295249109Sjkim { 296249109Sjkim AePrintException (FileId, Gbl_NextError, "\n[****iasl****]\n"); 297249109Sjkim Gbl_NextError = Gbl_NextError->Next; 298249109Sjkim } 299249109Sjkim 300249109Sjkim FlPrintFile (FileId, "\n"); 301249109Sjkim } 302249109Sjkim} 303249109Sjkim 304249109Sjkim 305249109Sjkim/******************************************************************************* 306249109Sjkim * 307249109Sjkim * FUNCTION: LsWriteListingHexBytes 308249109Sjkim * 309249109Sjkim * PARAMETERS: Buffer - AML code buffer 310249109Sjkim * Length - Number of AML bytes to write 311249109Sjkim * FileId - ID of current listing file. 312249109Sjkim * 313249109Sjkim * RETURN: None 314249109Sjkim * 315249109Sjkim * DESCRIPTION: Write the contents of the AML buffer to the listing file via 316249109Sjkim * the listing buffer. The listing buffer is flushed every 16 317249109Sjkim * AML bytes. 318249109Sjkim * 319249109Sjkim ******************************************************************************/ 320249109Sjkim 321249109Sjkimvoid 322249109SjkimLsWriteListingHexBytes ( 323249109Sjkim UINT8 *Buffer, 324249109Sjkim UINT32 Length, 325249109Sjkim UINT32 FileId) 326249109Sjkim{ 327249109Sjkim UINT32 i; 328249109Sjkim 329249109Sjkim 330249109Sjkim /* Transfer all requested bytes */ 331249109Sjkim 332249109Sjkim for (i = 0; i < Length; i++) 333249109Sjkim { 334249109Sjkim /* Print line header when buffer is empty */ 335249109Sjkim 336249109Sjkim if (Gbl_CurrentHexColumn == 0) 337249109Sjkim { 338249109Sjkim if (Gbl_HasIncludeFiles) 339249109Sjkim { 340249109Sjkim FlPrintFile (FileId, "%*s", 10, " "); 341249109Sjkim } 342249109Sjkim 343249109Sjkim switch (FileId) 344249109Sjkim { 345249109Sjkim case ASL_FILE_LISTING_OUTPUT: 346249109Sjkim 347249109Sjkim FlPrintFile (FileId, "%8.8X%s", Gbl_CurrentAmlOffset, 348249109Sjkim ASL_LISTING_LINE_PREFIX); 349249109Sjkim break; 350249109Sjkim 351249109Sjkim case ASL_FILE_ASM_SOURCE_OUTPUT: 352249109Sjkim 353249109Sjkim FlPrintFile (FileId, " db "); 354249109Sjkim break; 355249109Sjkim 356249109Sjkim case ASL_FILE_C_SOURCE_OUTPUT: 357249109Sjkim 358249109Sjkim FlPrintFile (FileId, " "); 359249109Sjkim break; 360249109Sjkim 361249109Sjkim default: 362250838Sjkim 363249109Sjkim /* No other types supported */ 364250838Sjkim 365249109Sjkim return; 366249109Sjkim } 367249109Sjkim } 368249109Sjkim 369249109Sjkim /* Transfer AML byte and update counts */ 370249109Sjkim 371249109Sjkim Gbl_AmlBuffer[Gbl_CurrentHexColumn] = Buffer[i]; 372249109Sjkim 373249109Sjkim Gbl_CurrentHexColumn++; 374249109Sjkim Gbl_CurrentAmlOffset++; 375249109Sjkim 376249109Sjkim /* Flush buffer when it is full */ 377249109Sjkim 378249109Sjkim if (Gbl_CurrentHexColumn >= HEX_LISTING_LINE_SIZE) 379249109Sjkim { 380249109Sjkim LsFlushListingBuffer (FileId); 381249109Sjkim } 382249109Sjkim } 383249109Sjkim} 384249109Sjkim 385249109Sjkim 386249109Sjkim/******************************************************************************* 387249109Sjkim * 388249109Sjkim * FUNCTION: LsWriteSourceLines 389249109Sjkim * 390249109Sjkim * PARAMETERS: ToLineNumber - 391249109Sjkim * ToLogicalLineNumber - Write up to this source line number 392249109Sjkim * FileId - ID of current listing file 393249109Sjkim * 394249109Sjkim * RETURN: None 395249109Sjkim * 396249109Sjkim * DESCRIPTION: Read then write source lines to the listing file until we have 397249109Sjkim * reached the specified logical (cumulative) line number. This 398249109Sjkim * automatically echos out comment blocks and other non-AML 399249109Sjkim * generating text until we get to the actual AML-generating line 400249109Sjkim * of ASL code specified by the logical line number. 401249109Sjkim * 402249109Sjkim ******************************************************************************/ 403249109Sjkim 404249109Sjkimvoid 405249109SjkimLsWriteSourceLines ( 406249109Sjkim UINT32 ToLineNumber, 407249109Sjkim UINT32 ToLogicalLineNumber, 408249109Sjkim UINT32 FileId) 409249109Sjkim{ 410249109Sjkim 411249109Sjkim /* Nothing to do for these file types */ 412249109Sjkim 413249109Sjkim if ((FileId == ASL_FILE_ASM_INCLUDE_OUTPUT) || 414249109Sjkim (FileId == ASL_FILE_C_INCLUDE_OUTPUT)) 415249109Sjkim { 416249109Sjkim return; 417249109Sjkim } 418249109Sjkim 419249109Sjkim Gbl_CurrentLine = ToLogicalLineNumber; 420249109Sjkim 421249109Sjkim /* Flush any hex bytes remaining from the last opcode */ 422249109Sjkim 423249109Sjkim LsFlushListingBuffer (FileId); 424249109Sjkim 425249109Sjkim /* Read lines and write them as long as we are not caught up */ 426249109Sjkim 427249109Sjkim if (Gbl_SourceLine < Gbl_CurrentLine) 428249109Sjkim { 429249109Sjkim /* 430249109Sjkim * If we just completed writing some AML hex bytes, output a linefeed 431249109Sjkim * to add some whitespace for readability. 432249109Sjkim */ 433249109Sjkim if (Gbl_HexBytesWereWritten) 434249109Sjkim { 435249109Sjkim FlPrintFile (FileId, "\n"); 436249109Sjkim Gbl_HexBytesWereWritten = FALSE; 437249109Sjkim } 438249109Sjkim 439249109Sjkim if (FileId == ASL_FILE_C_SOURCE_OUTPUT) 440249109Sjkim { 441249109Sjkim FlPrintFile (FileId, " /*\n"); 442249109Sjkim } 443249109Sjkim 444249109Sjkim /* Write one line at a time until we have reached the target line # */ 445249109Sjkim 446249109Sjkim while ((Gbl_SourceLine < Gbl_CurrentLine) && 447249109Sjkim LsWriteOneSourceLine (FileId)) 448249109Sjkim { ; } 449249109Sjkim 450249109Sjkim if (FileId == ASL_FILE_C_SOURCE_OUTPUT) 451249109Sjkim { 452249109Sjkim FlPrintFile (FileId, " */"); 453249109Sjkim } 454249109Sjkim 455249109Sjkim FlPrintFile (FileId, "\n"); 456249109Sjkim } 457249109Sjkim} 458249109Sjkim 459249109Sjkim 460249109Sjkim/******************************************************************************* 461249109Sjkim * 462249109Sjkim * FUNCTION: LsWriteOneSourceLine 463249109Sjkim * 464249109Sjkim * PARAMETERS: FileId - ID of current listing file 465249109Sjkim * 466249109Sjkim * RETURN: FALSE on EOF (input source file), TRUE otherwise 467249109Sjkim * 468249109Sjkim * DESCRIPTION: Read one line from the input source file and echo it to the 469249109Sjkim * listing file, prefixed with the line number, and if the source 470249109Sjkim * file contains include files, prefixed with the current filename 471249109Sjkim * 472249109Sjkim ******************************************************************************/ 473249109Sjkim 474249109SjkimUINT32 475249109SjkimLsWriteOneSourceLine ( 476249109Sjkim UINT32 FileId) 477249109Sjkim{ 478249109Sjkim UINT8 FileByte; 479249109Sjkim UINT32 Column = 0; 480249109Sjkim UINT32 Index = 16; 481249109Sjkim BOOLEAN StartOfLine = FALSE; 482249109Sjkim BOOLEAN ProcessLongLine = FALSE; 483249109Sjkim 484249109Sjkim 485249109Sjkim Gbl_SourceLine++; 486249109Sjkim Gbl_ListingNode->LineNumber++; 487249109Sjkim 488249109Sjkim /* Ignore lines that are completely blank (but count the line above) */ 489249109Sjkim 490249109Sjkim if (FlReadFile (ASL_FILE_SOURCE_OUTPUT, &FileByte, 1) != AE_OK) 491249109Sjkim { 492249109Sjkim return (0); 493249109Sjkim } 494249109Sjkim if (FileByte == '\n') 495249109Sjkim { 496249109Sjkim return (1); 497249109Sjkim } 498249109Sjkim 499249109Sjkim /* 500249109Sjkim * This is a non-empty line, we will print the entire line with 501249109Sjkim * the line number and possibly other prefixes and transforms. 502249109Sjkim */ 503249109Sjkim 504249109Sjkim /* Line prefixes for special files, C and ASM output */ 505249109Sjkim 506249109Sjkim if (FileId == ASL_FILE_C_SOURCE_OUTPUT) 507249109Sjkim { 508249109Sjkim FlPrintFile (FileId, " *"); 509249109Sjkim } 510249109Sjkim if (FileId == ASL_FILE_ASM_SOURCE_OUTPUT) 511249109Sjkim { 512249109Sjkim FlPrintFile (FileId, "; "); 513249109Sjkim } 514249109Sjkim 515249109Sjkim if (Gbl_HasIncludeFiles) 516249109Sjkim { 517249109Sjkim /* 518249109Sjkim * This file contains "include" statements, print the current 519249109Sjkim * filename and line number within the current file 520249109Sjkim */ 521249109Sjkim FlPrintFile (FileId, "%12s %5d%s", 522249109Sjkim Gbl_ListingNode->Filename, Gbl_ListingNode->LineNumber, 523249109Sjkim ASL_LISTING_LINE_PREFIX); 524249109Sjkim } 525249109Sjkim else 526249109Sjkim { 527249109Sjkim /* No include files, just print the line number */ 528249109Sjkim 529249109Sjkim FlPrintFile (FileId, "%8u%s", Gbl_SourceLine, 530249109Sjkim ASL_LISTING_LINE_PREFIX); 531249109Sjkim } 532249109Sjkim 533249109Sjkim /* Read the rest of this line (up to a newline or EOF) */ 534249109Sjkim 535249109Sjkim do 536249109Sjkim { 537249109Sjkim if (FileId == ASL_FILE_C_SOURCE_OUTPUT) 538249109Sjkim { 539249109Sjkim if (FileByte == '/') 540249109Sjkim { 541249109Sjkim FileByte = '*'; 542249109Sjkim } 543249109Sjkim } 544249109Sjkim 545249109Sjkim /* Split long input lines for readability in the listing */ 546249109Sjkim 547249109Sjkim Column++; 548249109Sjkim if (Column >= 128) 549249109Sjkim { 550249109Sjkim if (!ProcessLongLine) 551249109Sjkim { 552249109Sjkim if ((FileByte != '}') && 553249109Sjkim (FileByte != '{')) 554249109Sjkim { 555249109Sjkim goto WriteByte; 556249109Sjkim } 557249109Sjkim 558249109Sjkim ProcessLongLine = TRUE; 559249109Sjkim } 560249109Sjkim 561249109Sjkim if (FileByte == '{') 562249109Sjkim { 563249109Sjkim FlPrintFile (FileId, "\n%*s{\n", Index, " "); 564249109Sjkim StartOfLine = TRUE; 565249109Sjkim Index += 4; 566249109Sjkim continue; 567249109Sjkim } 568249109Sjkim 569249109Sjkim else if (FileByte == '}') 570249109Sjkim { 571249109Sjkim if (!StartOfLine) 572249109Sjkim { 573249109Sjkim FlPrintFile (FileId, "\n"); 574249109Sjkim } 575249109Sjkim 576249109Sjkim StartOfLine = TRUE; 577249109Sjkim Index -= 4; 578249109Sjkim FlPrintFile (FileId, "%*s}\n", Index, " "); 579249109Sjkim continue; 580249109Sjkim } 581249109Sjkim 582249109Sjkim /* Ignore spaces/tabs at the start of line */ 583249109Sjkim 584249109Sjkim else if ((FileByte == ' ') && StartOfLine) 585249109Sjkim { 586249109Sjkim continue; 587249109Sjkim } 588249109Sjkim 589249109Sjkim else if (StartOfLine) 590249109Sjkim { 591249109Sjkim StartOfLine = FALSE; 592249109Sjkim FlPrintFile (FileId, "%*s", Index, " "); 593249109Sjkim } 594249109Sjkim 595249109SjkimWriteByte: 596249109Sjkim FlWriteFile (FileId, &FileByte, 1); 597249109Sjkim if (FileByte == '\n') 598249109Sjkim { 599249109Sjkim /* 600249109Sjkim * This line has been completed. 601249109Sjkim * Check if an error occurred on this source line during the compile. 602249109Sjkim * If so, we print the error message after the source line. 603249109Sjkim */ 604249109Sjkim LsCheckException (Gbl_SourceLine, FileId); 605249109Sjkim return (1); 606249109Sjkim } 607249109Sjkim } 608249109Sjkim else 609249109Sjkim { 610249109Sjkim FlWriteFile (FileId, &FileByte, 1); 611249109Sjkim if (FileByte == '\n') 612249109Sjkim { 613249109Sjkim /* 614249109Sjkim * This line has been completed. 615249109Sjkim * Check if an error occurred on this source line during the compile. 616249109Sjkim * If so, we print the error message after the source line. 617249109Sjkim */ 618249109Sjkim LsCheckException (Gbl_SourceLine, FileId); 619249109Sjkim return (1); 620249109Sjkim } 621249109Sjkim } 622249109Sjkim 623249109Sjkim } while (FlReadFile (ASL_FILE_SOURCE_OUTPUT, &FileByte, 1) == AE_OK); 624249109Sjkim 625249109Sjkim /* EOF on the input file was reached */ 626249109Sjkim 627249109Sjkim return (0); 628249109Sjkim} 629249109Sjkim 630249109Sjkim 631249109Sjkim/******************************************************************************* 632249109Sjkim * 633249109Sjkim * FUNCTION: LsFlushListingBuffer 634249109Sjkim * 635249109Sjkim * PARAMETERS: FileId - ID of the listing file 636249109Sjkim * 637249109Sjkim * RETURN: None 638249109Sjkim * 639249109Sjkim * DESCRIPTION: Flush out the current contents of the 16-byte hex AML code 640249109Sjkim * buffer. Usually called at the termination of a single line 641249109Sjkim * of source code or when the buffer is full. 642249109Sjkim * 643249109Sjkim ******************************************************************************/ 644249109Sjkim 645249109Sjkimvoid 646249109SjkimLsFlushListingBuffer ( 647249109Sjkim UINT32 FileId) 648249109Sjkim{ 649249109Sjkim UINT32 i; 650249109Sjkim 651249109Sjkim 652249109Sjkim if (Gbl_CurrentHexColumn == 0) 653249109Sjkim { 654249109Sjkim return; 655249109Sjkim } 656249109Sjkim 657249109Sjkim /* Write the hex bytes */ 658249109Sjkim 659249109Sjkim switch (FileId) 660249109Sjkim { 661249109Sjkim case ASL_FILE_LISTING_OUTPUT: 662249109Sjkim 663249109Sjkim for (i = 0; i < Gbl_CurrentHexColumn; i++) 664249109Sjkim { 665249109Sjkim FlPrintFile (FileId, "%2.2X ", Gbl_AmlBuffer[i]); 666249109Sjkim } 667249109Sjkim 668249109Sjkim for (i = 0; i < ((HEX_LISTING_LINE_SIZE - Gbl_CurrentHexColumn) * 3); i++) 669249109Sjkim { 670249109Sjkim FlWriteFile (FileId, ".", 1); 671249109Sjkim } 672249109Sjkim 673249109Sjkim /* Write the ASCII character associated with each of the bytes */ 674249109Sjkim 675249109Sjkim LsDumpAscii (FileId, Gbl_CurrentHexColumn, Gbl_AmlBuffer); 676249109Sjkim break; 677249109Sjkim 678249109Sjkim 679249109Sjkim case ASL_FILE_ASM_SOURCE_OUTPUT: 680249109Sjkim 681249109Sjkim for (i = 0; i < Gbl_CurrentHexColumn; i++) 682249109Sjkim { 683249109Sjkim if (i > 0) 684249109Sjkim { 685249109Sjkim FlPrintFile (FileId, ","); 686249109Sjkim } 687298714Sjkim 688249109Sjkim FlPrintFile (FileId, "0%2.2Xh", Gbl_AmlBuffer[i]); 689249109Sjkim } 690249109Sjkim 691249109Sjkim for (i = 0; i < ((HEX_LISTING_LINE_SIZE - Gbl_CurrentHexColumn) * 5); i++) 692249109Sjkim { 693249109Sjkim FlWriteFile (FileId, " ", 1); 694249109Sjkim } 695249109Sjkim 696249109Sjkim FlPrintFile (FileId, " ;%8.8X", 697249109Sjkim Gbl_CurrentAmlOffset - HEX_LISTING_LINE_SIZE); 698249109Sjkim 699249109Sjkim /* Write the ASCII character associated with each of the bytes */ 700249109Sjkim 701249109Sjkim LsDumpAscii (FileId, Gbl_CurrentHexColumn, Gbl_AmlBuffer); 702249109Sjkim break; 703249109Sjkim 704249109Sjkim 705249109Sjkim case ASL_FILE_C_SOURCE_OUTPUT: 706249109Sjkim 707249109Sjkim for (i = 0; i < Gbl_CurrentHexColumn; i++) 708249109Sjkim { 709249109Sjkim FlPrintFile (FileId, "0x%2.2X,", Gbl_AmlBuffer[i]); 710249109Sjkim } 711249109Sjkim 712249109Sjkim /* Pad hex output with spaces if line is shorter than max line size */ 713249109Sjkim 714249109Sjkim for (i = 0; i < ((HEX_LISTING_LINE_SIZE - Gbl_CurrentHexColumn) * 5); i++) 715249109Sjkim { 716249109Sjkim FlWriteFile (FileId, " ", 1); 717249109Sjkim } 718249109Sjkim 719249109Sjkim /* AML offset for the start of the line */ 720249109Sjkim 721249109Sjkim FlPrintFile (FileId, " /* %8.8X", 722249109Sjkim Gbl_CurrentAmlOffset - Gbl_CurrentHexColumn); 723249109Sjkim 724249109Sjkim /* Write the ASCII character associated with each of the bytes */ 725249109Sjkim 726249109Sjkim LsDumpAsciiInComment (FileId, Gbl_CurrentHexColumn, Gbl_AmlBuffer); 727249109Sjkim FlPrintFile (FileId, " */"); 728249109Sjkim break; 729249109Sjkim 730249109Sjkim default: 731250838Sjkim 732249109Sjkim /* No other types supported */ 733250838Sjkim 734249109Sjkim return; 735249109Sjkim } 736249109Sjkim 737249109Sjkim FlPrintFile (FileId, "\n"); 738249109Sjkim 739249109Sjkim Gbl_CurrentHexColumn = 0; 740249109Sjkim Gbl_HexBytesWereWritten = TRUE; 741249109Sjkim} 742249109Sjkim 743249109Sjkim 744249109Sjkim/******************************************************************************* 745249109Sjkim * 746249109Sjkim * FUNCTION: LsPushNode 747249109Sjkim * 748249109Sjkim * PARAMETERS: Filename - Pointer to the include filename 749249109Sjkim * 750249109Sjkim * RETURN: None 751249109Sjkim * 752249109Sjkim * DESCRIPTION: Push a listing node on the listing/include file stack. This 753249109Sjkim * stack enables tracking of include files (infinitely nested) 754249109Sjkim * and resumption of the listing of the parent file when the 755249109Sjkim * include file is finished. 756249109Sjkim * 757249109Sjkim ******************************************************************************/ 758249109Sjkim 759249109Sjkimvoid 760249109SjkimLsPushNode ( 761249109Sjkim char *Filename) 762249109Sjkim{ 763249109Sjkim ASL_LISTING_NODE *Lnode; 764249109Sjkim 765249109Sjkim 766249109Sjkim /* Create a new node */ 767249109Sjkim 768249109Sjkim Lnode = UtLocalCalloc (sizeof (ASL_LISTING_NODE)); 769249109Sjkim 770249109Sjkim /* Initialize */ 771249109Sjkim 772249109Sjkim Lnode->Filename = Filename; 773249109Sjkim Lnode->LineNumber = 0; 774249109Sjkim 775249109Sjkim /* Link (push) */ 776249109Sjkim 777249109Sjkim Lnode->Next = Gbl_ListingNode; 778249109Sjkim Gbl_ListingNode = Lnode; 779249109Sjkim} 780249109Sjkim 781249109Sjkim 782249109Sjkim/******************************************************************************* 783249109Sjkim * 784249109Sjkim * FUNCTION: LsPopNode 785249109Sjkim * 786249109Sjkim * PARAMETERS: None 787249109Sjkim * 788249109Sjkim * RETURN: List head after current head is popped off 789249109Sjkim * 790249109Sjkim * DESCRIPTION: Pop the current head of the list, free it, and return the 791249109Sjkim * next node on the stack (the new current node). 792249109Sjkim * 793249109Sjkim ******************************************************************************/ 794249109Sjkim 795249109SjkimASL_LISTING_NODE * 796249109SjkimLsPopNode ( 797249109Sjkim void) 798249109Sjkim{ 799249109Sjkim ASL_LISTING_NODE *Lnode; 800249109Sjkim 801249109Sjkim 802249109Sjkim /* Just grab the node at the head of the list */ 803249109Sjkim 804249109Sjkim Lnode = Gbl_ListingNode; 805249109Sjkim if ((!Lnode) || 806249109Sjkim (!Lnode->Next)) 807249109Sjkim { 808249109Sjkim AslError (ASL_ERROR, ASL_MSG_COMPILER_INTERNAL, NULL, 809249109Sjkim "Could not pop empty listing stack"); 810249109Sjkim return (Gbl_ListingNode); 811249109Sjkim } 812249109Sjkim 813249109Sjkim Gbl_ListingNode = Lnode->Next; 814249109Sjkim ACPI_FREE (Lnode); 815249109Sjkim 816249109Sjkim /* New "Current" node is the new head */ 817249109Sjkim 818249109Sjkim return (Gbl_ListingNode); 819249109Sjkim} 820