exconvrt.c revision 199767f8919635c4928607450d9e0abb932109ce
/******************************************************************************
*
* Module Name: exconvrt - Object conversion routines
*
*****************************************************************************/
/*
* 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.
*/
#define _COMPONENT ACPI_EXECUTER
ACPI_MODULE_NAME ("exconvrt")
/* Local prototypes */
static UINT32
/*******************************************************************************
*
* FUNCTION: AcpiExConvertToInteger
*
* PARAMETERS: ObjDesc - Object to be converted. Must be an
* Integer, Buffer, or String
* ResultDesc - Where the new Integer object is returned
* Flags - Used for string conversion
*
* RETURN: Status
*
* DESCRIPTION: Convert an ACPI Object to an integer.
*
******************************************************************************/
{
UINT32 i;
{
case ACPI_TYPE_INTEGER:
/* No conversion necessary */
*ResultDesc = ObjDesc;
case ACPI_TYPE_BUFFER:
case ACPI_TYPE_STRING:
break;
default:
}
/*
* strings are treated as raw data - we don't convert ascii to hex for
* strings.
*
* There are two terminating conditions for the loop:
* 1) The size of an integer has been reached, or
* 2) The end of the buffer or string has been reached
*/
Result = 0;
/* String conversion is different than Buffer conversion */
{
case ACPI_TYPE_STRING:
/*
* Convert string to an integer - for most cases, the string must be
* hexadecimal as per the ACPI specification. The only exception (as
* of ACPI 3.0) is that the ToInteger() operator allows both decimal
* and hexadecimal strings (hex prefixed with "0x").
*/
if (ACPI_FAILURE (Status))
{
}
break;
case ACPI_TYPE_BUFFER:
/* Check for zero-length buffer */
if (!Count)
{
}
/* Transfer no more than an integer's worth of data */
if (Count > AcpiGbl_IntegerByteWidth)
{
}
/*
* Convert buffer to an integer - we simply grab enough raw data
* from the buffer to fill an integer
*/
for (i = 0; i < Count; i++)
{
/*
* Get next byte and shift it into the Result.
* Little endian is used, meaning that the first byte of the buffer
* is the LSB of the integer
*/
}
break;
default:
/* No other types can get here */
break;
}
/* Create a new integer */
if (!ReturnDesc)
{
}
ACPI_FORMAT_UINT64 (Result)));
/* Save the Result */
(void) AcpiExTruncateFor32bitTable (ReturnDesc);
*ResultDesc = ReturnDesc;
}
/*******************************************************************************
*
* FUNCTION: AcpiExConvertToBuffer
*
* PARAMETERS: ObjDesc - Object to be converted. Must be an
* Integer, Buffer, or String
* ResultDesc - Where the new buffer object is returned
*
* RETURN: Status
*
* DESCRIPTION: Convert an ACPI Object to a Buffer
*
******************************************************************************/
{
{
case ACPI_TYPE_BUFFER:
/* No conversion necessary */
*ResultDesc = ObjDesc;
case ACPI_TYPE_INTEGER:
/*
* Create a new Buffer object.
* Need enough space for one integer
*/
if (!ReturnDesc)
{
}
/* Copy the integer to the buffer, LSB first */
break;
case ACPI_TYPE_STRING:
/*
* Create a new Buffer object
* Size will be the string length
*
* NOTE: Add one to the string length to include the null terminator.
* The ACPI spec is unclear on this subject, but there is existing
* buffer.
*/
if (!ReturnDesc)
{
}
/* Copy the string to the buffer */
break;
default:
}
/* Mark buffer initialized */
*ResultDesc = ReturnDesc;
}
/*******************************************************************************
*
* FUNCTION: AcpiExConvertToAscii
*
* PARAMETERS: Integer - Value to be converted
* Base - ACPI_STRING_DECIMAL or ACPI_STRING_HEX
* String - Where the string is returned
* DataWidth - Size of data item to be converted, in bytes
*
* RETURN: Actual string length
*
* DESCRIPTION: Convert an ACPI Integer to a hex or decimal string
*
******************************************************************************/
static UINT32
{
UINT32 i;
UINT32 j;
UINT32 k = 0;
switch (Base)
{
case 10:
/* Setup max length for the decimal number */
switch (DataWidth)
{
case 1:
break;
case 4:
break;
case 8:
default:
break;
}
Remainder = 0;
for (i = DecimalLength; i > 0; i--)
{
/* Divide by nth factor of 10 */
for (j = 0; j < i; j++)
{
}
/* Handle leading zeros */
if (Remainder != 0)
{
}
if (!SupressZeros)
{
k++;
}
}
break;
case 16:
/* HexLength: 2 ascii hex chars per data byte */
{
/* Get one hex digit, most significant digits first */
k++;
}
break;
default:
return (0);
}
/*
* Since leading zeros are suppressed, we must check for the case where
* the integer equals 0
*
* Finally, null terminate the string and return the length
*/
if (!k)
{
String [0] = ACPI_ASCII_ZERO;
k = 1;
}
String [k] = 0;
return ((UINT32) k);
}
/*******************************************************************************
*
* FUNCTION: AcpiExConvertToString
*
* PARAMETERS: ObjDesc - Object to be converted. Must be an
* Integer, Buffer, or String
* ResultDesc - Where the string object is returned
* Type - String flags (base and conversion type)
*
* RETURN: Status
*
* DESCRIPTION: Convert an ACPI Object to a string
*
******************************************************************************/
{
UINT32 i;
UINT32 StringLength = 0;
{
case ACPI_TYPE_STRING:
/* No conversion necessary */
*ResultDesc = ObjDesc;
case ACPI_TYPE_INTEGER:
switch (Type)
{
/* Make room for maximum decimal number */
Base = 10;
break;
default:
/* Two hex string characters for each integer byte */
break;
}
/*
* Create a new String
* Need enough space for one ASCII integer (plus null terminator)
*/
if (!ReturnDesc)
{
}
/* Convert integer to string */
/* Null terminate at the correct place */
NewBuf [StringLength] = 0;
break;
case ACPI_TYPE_BUFFER:
/* Setup string length, base, and separator */
switch (Type)
{
case ACPI_EXPLICIT_CONVERT_DECIMAL: /* Used by ToDecimalString */
/*
* From ACPI: "If Data is a buffer, it is converted to a string of
* decimal values separated by commas."
*/
Base = 10;
/*
* Calculate the final string length. Individual string values
* are variable length (include separator for each)
*/
{
{
StringLength += 4;
}
{
StringLength += 3;
}
else
{
StringLength += 2;
}
}
break;
/*
* From the ACPI spec:
*"The entire contents of the buffer are converted to a string of
* two-character hexadecimal numbers, each separated by a space."
*/
Separator = ' ';
break;
case ACPI_EXPLICIT_CONVERT_HEX: /* Used by ToHexString */
/*
* From ACPI: "If Data is a buffer, it is converted to a string of
* hexadecimal values separated by commas."
*/
break;
default:
}
/*
* Create a new string object and string buffer
* (-1 because of extra separator included in StringLength from above)
* Allow creation of zero-length strings from zero-length buffers.
*/
if (StringLength)
{
StringLength--;
}
if (!ReturnDesc)
{
}
/*
* Convert buffer bytes to hex or decimal values
* (separated by commas or spaces)
*/
{
NewBuf, 1);
}
/*
* Null terminate the string
*/
{
NewBuf--;
}
*NewBuf = 0;
break;
default:
}
*ResultDesc = ReturnDesc;
}
/*******************************************************************************
*
* FUNCTION: AcpiExConvertToTargetType
*
* PARAMETERS: DestinationType - Current type of the destination
* SourceDesc - Source object to be converted.
* ResultDesc - Where the converted object is returned
* WalkState - Current method state
*
* RETURN: Status
*
* DESCRIPTION: Implements "implicit conversion" rules for storing an object.
*
******************************************************************************/
{
/* Default behavior */
*ResultDesc = SourceDesc;
/*
* If required by the target,
* perform implicit conversion on the source before we store it.
*/
{
case ARGI_SIMPLE_TARGET:
case ARGI_FIXED_TARGET:
case ARGI_INTEGER_REF: /* Handles Increment, Decrement cases */
switch (DestinationType)
{
/*
* Named field can always handle conversions
*/
break;
default:
/* No conversion allowed for these types */
{
"Explicit operator, will store (%s) over existing type (%s)\n",
}
}
break;
case ARGI_TARGETREF:
switch (DestinationType)
{
case ACPI_TYPE_INTEGER:
case ACPI_TYPE_BUFFER_FIELD:
/*
* These types require an Integer operand. We can convert
* a Buffer or a String to an Integer if necessary.
*/
16);
break;
case ACPI_TYPE_STRING:
/*
* The operand must be a String. We can convert an
* Integer or Buffer if necessary
*/
break;
case ACPI_TYPE_BUFFER:
/*
* The operand must be a Buffer. We can convert an
* Integer or String if necessary
*/
break;
default:
break;
}
break;
case ARGI_REFERENCE:
/*
* CreateXxxxField cases - we are storing the field object into the name
*/
break;
default:
"Unknown Target type ID 0x%X AmlOpcode 0x%X DestType %s",
}
/*
* Source-to-Target conversion semantics:
*
* If conversion to the target type cannot be performed, then simply
* overwrite the target with the new object and type.
*/
{
}
}