aslutils.c revision 199767f8919635c4928607450d9e0abb932109ce
/******************************************************************************
*
* Module Name: aslutils -- compiler utilities
*
*****************************************************************************/
/*
* Copyright (C) 2000 - 2015, Intel Corp.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions, and the following disclaimer,
* without modification.
* 2. Redistributions in binary form must reproduce at minimum a disclaimer
* substantially similar to the "NO WARRANTY" disclaimer below
* ("Disclaimer") and any redistribution must be conditioned upon
* including a substantially similar Disclaimer requirement for further
* binary redistribution.
* 3. Neither the names of the above-listed copyright holders nor the names
* of any contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* Alternatively, this software may be distributed under the terms of the
* GNU General Public License ("GPL") version 2 as published by the Free
* Software Foundation.
*
* NO WARRANTY
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGES.
*/
#include "aslcompiler.y.h"
#define _COMPONENT ACPI_COMPILER
ACPI_MODULE_NAME ("aslutils")
/* Local prototypes */
static void
char *NameSeg,
char *PaddedNameSeg);
static void
char *Name);
/*******************************************************************************
*
* FUNCTION: UtDisplaySupportedTables
*
* PARAMETERS: None
*
* RETURN: None
*
* DESCRIPTION: Print all supported ACPI table names.
*
******************************************************************************/
void
void)
{
UINT32 i;
printf ("\nACPI tables supported by iASL version %8.8X:\n"
" (Compiler, Disassembler, Template Generator)\n\n",
/* All ACPI tables with the common table header */
printf ("\n Supported ACPI tables:\n");
{
printf ("%8u) %s %s\n", i,
}
}
/*******************************************************************************
*
* FUNCTION: UtDisplayConstantOpcodes
*
* PARAMETERS: None
*
* RETURN: None
*
* DESCRIPTION: Print AML opcodes that can be used in constant expressions.
*
******************************************************************************/
void
void)
{
UINT32 i;
printf ("Constant expression opcode information\n\n");
for (i = 0; i < sizeof (AcpiGbl_AmlOpInfo) / sizeof (ACPI_OPCODE_INFO); i++)
{
{
}
}
}
/*******************************************************************************
*
* FUNCTION: UtLocalCalloc
*
* PARAMETERS: Size - Bytes to be allocated
*
* RETURN: Pointer to the allocated memory. Guaranteed to be valid.
*
* DESCRIPTION: Allocate zero-initialized memory. Aborts the compile on an
* allocation failure, on the assumption that nothing more can be
* accomplished.
*
******************************************************************************/
void *
{
void *Allocated;
if (!Allocated)
{
CmCleanupAndExit ();
exit (1);
}
TotalAllocated += Size;
return (Allocated);
}
/*******************************************************************************
*
* FUNCTION: UtBeginEvent
*
* PARAMETERS: Name - Ascii name of this event
*
* RETURN: Event number (integer index)
*
* DESCRIPTION: Saves the current time with this event
*
******************************************************************************/
char *Name)
{
if (AslGbl_NextEvent >= ASL_NUM_EVENTS)
{
AcpiOsPrintf ("Ran out of compiler event structs!\n");
return (AslGbl_NextEvent);
}
/* Init event with current (start) time */
return (AslGbl_NextEvent++);
}
/*******************************************************************************
*
* FUNCTION: UtEndEvent
*
* PARAMETERS: Event - Event number (integer index)
*
* RETURN: None
*
* DESCRIPTION: Saves the current time (end time) with this event
*
******************************************************************************/
void
{
if (Event >= ASL_NUM_EVENTS)
{
return;
}
/* Insert end time for event */
}
/*******************************************************************************
*
* FUNCTION: UtConvertByteToHex
*
* PARAMETERS: RawByte - Binary data
* Buffer - Pointer to where the hex bytes will be
* stored
*
* RETURN: Ascii hex byte is stored in Buffer.
*
* DESCRIPTION: Perform hex-to-ascii translation. The return data is prefixed
* with "0x"
*
******************************************************************************/
void
{
Buffer[0] = '0';
}
/*******************************************************************************
*
* FUNCTION: UtConvertByteToAsmHex
*
* PARAMETERS: RawByte - Binary data
* Buffer - Pointer to where the hex bytes will be
* stored
*
* RETURN: Ascii hex byte is stored in Buffer.
*
* DESCRIPTION: Perform hex-to-ascii translation. The return data is prefixed
* with '0', and a trailing 'h' is added.
*
******************************************************************************/
void
{
Buffer[0] = '0';
}
/*******************************************************************************
*
* FUNCTION: DbgPrint
*
* PARAMETERS: Type - Type of output
* Fmt - Printf format string
* ... - variable printf list
*
* RETURN: None
*
* DESCRIPTION: Conditional print statement. Prints to stderr only if the
* debug flag is set.
*
******************************************************************************/
void
DbgPrint (
char *Fmt,
...)
{
if (!Gbl_DebugFlag)
{
return;
}
if ((Type == ASL_PARSE_OUTPUT) &&
(!(AslCompilerdebug)))
{
return;
}
return;
}
/*******************************************************************************
*
* FUNCTION: UtPrintFormattedName
*
* PARAMETERS: ParseOpcode - Parser keyword ID
* Level - Indentation level
*
* RETURN: None
*
* DESCRIPTION: Print the ascii name of the parse opcode.
*
******************************************************************************/
#define TEXT_OFFSET 10
void
{
if (Level)
{
}
if (Level < TEXT_OFFSET)
{
}
}
/*******************************************************************************
*
* FUNCTION: UtSetParseOpName
*
* PARAMETERS: Op - Parse op to be named.
*
* RETURN: None
*
* DESCRIPTION: Insert the ascii name of the parse opcode
*
******************************************************************************/
void
{
}
/*******************************************************************************
*
* FUNCTION: UtDisplaySummary
*
* PARAMETERS: FileID - ID of outpout file
*
* RETURN: None
*
* DESCRIPTION: Display compilation statistics
*
******************************************************************************/
void
{
UINT32 i;
if (FileId != ASL_FILE_STDOUT)
{
/* Compiler name and version number */
}
/* Summary of main input and output files */
{
"%-14s %s - %u lines, %u bytes, %u fields\n",
"Table Input:",
{
"%-14s %s - %u bytes\n",
"Binary Output:",
}
}
else
{
"%-14s %s - %u lines, %u bytes, %u keywords\n",
"ASL Input:",
/* AML summary */
{
{
"%-14s %s - %u bytes, %u named objects, %u executable opcodes\n",
"AML Output:",
}
}
}
/* Display summary of any optional files */
for (i = ASL_FILE_SOURCE_OUTPUT; i <= ASL_MAX_FILE_TYPE; i++)
{
{
continue;
}
/* .SRC is a temp file unless specifically requested */
if ((i == ASL_FILE_SOURCE_OUTPUT) && (!Gbl_SourceOutputFlag))
{
continue;
}
/* .PRE is the preprocessor intermediate file */
if ((i == ASL_FILE_PREPROCESSOR) && (!Gbl_KeepPreprocessorTempFile))
{
continue;
}
}
/* Error summary */
"\nCompilation complete. %u Errors, %u Warnings, %u Remarks",
{
if (TotalFolds)
{
}
}
}
/*******************************************************************************
*
* FUNCTION: UtCheckIntegerRange
*
* PARAMETERS: Op - Integer parse node
* LowValue - Smallest allowed value
* HighValue - Largest allowed value
*
* RETURN: Op if OK, otherwise NULL
*
* DESCRIPTION: Check integer for an allowable range
*
******************************************************************************/
{
if (!Op)
{
return (NULL);
}
{
return (NULL);
}
return (Op);
}
/*******************************************************************************
*
* FUNCTION: UtStringCacheCalloc
*
* PARAMETERS: Length - Size of buffer requested
*
* RETURN: Pointer to the buffer. Aborts on allocation failure
*
* DESCRIPTION: Allocate a string buffer. Bypass the local
* dynamic memory manager for performance reasons (This has a
* major impact on the speed of the compiler.)
*
******************************************************************************/
char *
{
char *Buffer;
{
if (Gbl_StringCacheList)
{
/* Link new cache buffer just following head of list */
/* Leave cache management pointers alone as they pertain to head */
Gbl_StringSize += Length;
}
}
{
/* Allocate a new buffer */
/* Link new cache buffer to head of list */
/* Setup cache management pointers */
}
Gbl_StringSize += Length;
return (Buffer);
}
/******************************************************************************
*
* FUNCTION: UtExpandLineBuffers
*
* PARAMETERS: None. Updates global line buffer pointers.
*
* RETURN: None. Reallocates the global line buffers
*
* DESCRIPTION: Called if the current line buffer becomes filled. Reallocates
* all global line buffers and updates Gbl_LineBufferSize. NOTE:
* Also used for the initial allocation of the buffers, when
* all of the buffer pointers are NULL. Initial allocations are
* of size ASL_DEFAULT_LINE_BUFFER_SIZE
*
*****************************************************************************/
void
void)
{
/* Attempt to double the size of all line buffers */
{
"Increasing line buffer size from %u to %u\n",
}
if (!Gbl_CurrentLineBuffer)
{
goto ErrorExit;
}
if (!Gbl_MainTokenBuffer)
{
goto ErrorExit;
}
if (!Gbl_MacroTokenBuffer)
{
goto ErrorExit;
}
{
goto ErrorExit;
}
return;
/* On error above, simply issue error messages and abort, cannot continue */
printf ("Could not increase line buffer size from %u to %u\n",
AslAbort ();
}
/******************************************************************************
*
* FUNCTION: UtFreeLineBuffers
*
* PARAMETERS: None
*
* RETURN: None
*
* DESCRIPTION: Free all line buffers
*
*****************************************************************************/
void
void)
{
}
/*******************************************************************************
*
* FUNCTION: UtInternalizeName
*
* PARAMETERS: ExternalName - Name to convert
* ConvertedName - Where the converted name is returned
*
* RETURN: Status
*
* DESCRIPTION: Convert an external (ASL) name to an internal (AML) name
*
******************************************************************************/
char *ExternalName,
char **ConvertedName)
{
if (!ExternalName)
{
return (AE_OK);
}
/* Get the length of the new internal name */
/* We need a segment to store the internal name */
if (!Info.InternalName)
{
return (AE_NO_MEMORY);
}
/* Build the name */
if (ACPI_FAILURE (Status))
{
return (Status);
}
return (AE_OK);
}
/*******************************************************************************
*
* FUNCTION: UtPadNameWithUnderscores
*
* PARAMETERS: NameSeg - Input nameseg
* PaddedNameSeg - Output padded nameseg
*
* RETURN: Padded nameseg.
*
* DESCRIPTION: Pads a NameSeg with underscores if necessary to form a full
* ACPI_NAME.
*
******************************************************************************/
static void
char *NameSeg,
char *PaddedNameSeg)
{
UINT32 i;
for (i = 0; (i < ACPI_NAME_SIZE); i++)
{
if (*NameSeg)
{
*PaddedNameSeg = *NameSeg;
NameSeg++;
}
else
{
*PaddedNameSeg = '_';
}
}
}
/*******************************************************************************
*
* FUNCTION: UtAttachNameseg
*
* PARAMETERS: Op - Parent parse node
* Name - Full ExternalName
*
* RETURN: None; Sets the NameSeg field in parent node
*
* DESCRIPTION: Extract the last nameseg of the ExternalName and store it
* in the NameSeg field of the Op.
*
******************************************************************************/
static void
char *Name)
{
char *NameSeg;
char PaddedNameSeg[4];
if (!Name)
{
return;
}
/* Look for the last dot in the namepath */
if (NameSeg)
{
/* Found last dot, we have also found the final nameseg */
NameSeg++;
}
else
{
/* No dots in the namepath, there is only a single nameseg. */
/* Handle prefixes */
while (ACPI_IS_ROOT_PREFIX (*Name) ||
{
Name++;
}
/* Remaining string should be one single nameseg */
}
}
/*******************************************************************************
*
* FUNCTION: UtAttachNamepathToOwner
*
* PARAMETERS: Op - Parent parse node
* NameOp - Node that contains the name
*
* RETURN: Sets the ExternalName and Namepath in the parent node
*
* DESCRIPTION: Store the name in two forms in the parent node: The original
* (external) name, and the internalized name that is used within
* the ACPI namespace manager.
*
******************************************************************************/
void
{
/* Full external path */
/* Save the NameOp for possible error reporting later */
/* Last nameseg of the path */
/* Create internalized path */
if (ACPI_FAILURE (Status))
{
/* TBD: abort on no memory */
}
}
/*******************************************************************************
*
* FUNCTION: UtDoConstant
*
* PARAMETERS: String - Hex, Octal, or Decimal string
*
* RETURN: Converted Integer
*
* DESCRIPTION: Convert a string to an integer, with error checking.
*
******************************************************************************/
char *String)
{
char ErrBuf[64];
if (ACPI_FAILURE (Status))
{
}
return (Converted);
}
/* TBD: use version in ACPICA main code base? */
/*******************************************************************************
*
* FUNCTION: stroul64
*
* PARAMETERS: String - Null terminated string
* Terminater - Where a pointer to the terminating byte
* is returned
* Base - Radix of the string
*
* RETURN: Converted value
*
* DESCRIPTION: Convert a string into an unsigned value.
*
******************************************************************************/
stroul64 (
char *String,
{
UINT64 ReturnValue = 0;
*RetInteger = 0;
switch (Base)
{
case 0:
case 8:
case 10:
case 16:
break;
default:
/*
* The specified Base parameter is not in the domain of
* this function:
*/
return (AE_BAD_PARAMETER);
}
/* Skip over any white space in the buffer: */
{
++String;
}
/*
* The buffer may contain an optional plus or minus sign.
* If it does, then skip over it but remember what is was:
*/
if (*String == '-')
{
++String;
}
else if (*String == '+')
{
++String;
}
else
{
}
/*
* If the input parameter Base is zero, then we need to
* determine if it is octal, decimal, or hexadecimal:
*/
if (Base == 0)
{
if (*String == '0')
{
{
Base = 16;
++String;
}
else
{
Base = 8;
}
}
else
{
Base = 10;
}
}
/*
* For octal and hexadecimal bases, skip over the leading
* 0 or 0x, if they are present.
*/
{
String++;
}
if (Base == 16 &&
*String == '0' &&
{
String++;
}
/* Main loop: convert the string to an unsigned long */
while (*String)
{
{
}
else
{
{
}
else
{
goto ErrorExit;
}
}
{
goto ErrorExit;
}
/* Check to see if value is out of range: */
{
goto ErrorExit;
}
else
{
ReturnValue *= Base;
ReturnValue += Index;
}
++String;
}
/* If a minus sign was present, then "the conversion is negated": */
if (Sign == ACPI_SIGN_NEGATIVE)
{
}
return (Status);
switch (Base)
{
case 8:
break;
case 10:
break;
case 16:
break;
default:
/* Base validated above */
break;
}
return (Status);
}