/*******************************************************************************
*
* Module Name: dmbuffer - AML disassembler, buffer and string support
*
******************************************************************************/
/*
* Copyright (C) 2000 - 2016, 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 "acpi.h"
#include "accommon.h"
#include "acutils.h"
#include "acdisasm.h"
#include "acparser.h"
#include "amlcode.h"
#include "acinterp.h"
ACPI_MODULE_NAME ("dmbuffer")
/* Local prototypes */
static void
static void
static void
static void
static const char *
const char **List);
/*******************************************************************************
*
* FUNCTION: AcpiDmDisasmByteList
*
* PARAMETERS: Level - Current source code indentation level
* ByteData - Pointer to the byte list
* ByteCount - Length of the byte list
*
* RETURN: None
*
* DESCRIPTION: Dump an AML "ByteList" in Hex format. 8 bytes per line, prefixed
* with the hex buffer offset.
*
******************************************************************************/
void
{
UINT32 i;
UINT32 j;
if (!ByteCount)
{
return;
}
for (i = 0; i < ByteCount; i += ACPI_BUFFER_BYTES_PER_LINE)
{
/* Line indent and offset prefix for each new line */
{
AcpiOsPrintf ("/* %04X */ ", i);
}
/* Dump the actual hex values */
for (j = 0; j < ACPI_BUFFER_BYTES_PER_LINE; j++)
{
CurrentIndex = i + j;
if (CurrentIndex >= ByteCount)
{
/* Dump fill spaces */
AcpiOsPrintf (" ");
continue;
}
/* Add comma if there are more bytes to display */
{
AcpiOsPrintf (",");
}
else
{
AcpiOsPrintf (" ");
}
}
/* Dump the ASCII equivalents within a comment */
AcpiOsPrintf (" /* ");
for (j = 0; j < ACPI_BUFFER_BYTES_PER_LINE; j++)
{
CurrentIndex = i + j;
if (CurrentIndex >= ByteCount)
{
break;
}
{
}
else
{
AcpiOsPrintf (".");
}
}
/* Finished with this line */
AcpiOsPrintf (" */\n");
}
}
/*******************************************************************************
*
* FUNCTION: AcpiDmByteList
*
* PARAMETERS: Info - Parse tree walk info
* Op - Byte list op
*
* RETURN: None
*
* DESCRIPTION: Dump a buffer byte list, handling the various types of buffers.
* Buffer type must be already set in the Op DisasmOpcode.
*
******************************************************************************/
void
{
/*
* The byte list belongs to a buffer, and can be produced by either
* a ResourceTemplate, Unicode, quoted string, or a plain byte list.
*/
{
case ACPI_DASM_RESOURCE:
break;
case ACPI_DASM_STRING:
AcpiOsPrintf ("\n");
break;
case ACPI_DASM_UUID:
AcpiDmUuid (Op);
break;
case ACPI_DASM_UNICODE:
AcpiDmUnicode (Op);
break;
case ACPI_DASM_PLD_METHOD:
#if 0
#endif
break;
case ACPI_DASM_BUFFER:
default:
/*
* Not a resource, string, or unicode string.
* Just dump the buffer
*/
break;
}
}
/*******************************************************************************
*
* FUNCTION: AcpiDmIsUuidBuffer
*
* PARAMETERS: Op - Buffer Object to be examined
*
* RETURN: TRUE if buffer contains a UUID
*
* DESCRIPTION: Determine if a buffer Op contains a UUID
*
* To help determine whether the buffer is a UUID versus a raw data buffer,
* there a are a couple bytes we can look at:
*
* xxxxxxxx-xxxx-Mxxx-Nxxx-xxxxxxxxxxxx
*
* The variant covered by the UUID specification is indicated by the two most
* significant bits of N being 1 0 (i.e., the hexadecimal N will always be
* 8, 9, A, or B).
*
* The variant covered by the UUID specification has five versions. For this
* variant, the four bits of M indicates the UUID version (i.e., the
* hexadecimal M will be either 1, 2, 3, 4, or 5).
*
******************************************************************************/
{
/* Buffer size is the buffer argument */
/* Next, the initializer byte list to examine */
if (!NextOp)
{
return (FALSE);
}
/* Extract the byte list info */
/* Byte count must be exactly 16 */
if (ByteCount != UUID_BUFFER_LENGTH)
{
return (FALSE);
}
/* Check for valid "M" and "N" values (see function header above) */
{
return (FALSE);
}
/* Ignore the Size argument in the disassembly of this buffer op */
return (TRUE);
}
/*******************************************************************************
*
* FUNCTION: AcpiDmUuid
*
* PARAMETERS: Op - Byte List op containing a UUID
*
* RETURN: None
*
* DESCRIPTION: Dump a buffer containing a UUID as a standard ASCII string.
*
* Output Format:
* In its canonical form, the UUID is represented by a string containing 32
* lowercase hexadecimal digits, displayed in 5 groups separated by hyphens.
* The complete form is 8-4-4-4-12 for a total of 36 characters (32
* alphanumeric characters representing hex digits and 4 hyphens). In bytes,
* 4-2-2-2-6. Example:
*
* ToUUID ("107ededd-d381-4fd7-8da9-08e9a6c79644")
*
******************************************************************************/
static void
{
const char *Description;
"\"%2.2x%2.2x%2.2x%2.2x-"
"%2.2x%2.2x-"
"%2.2x%2.2x-"
"%2.2x%2.2x-"
"%2.2x%2.2x%2.2x%2.2x%2.2x%2.2x\")",
#ifdef ACPI_APPLICATION
/* Dump the UUID description string if available */
if (Description)
{
}
#endif
}
/*******************************************************************************
*
* FUNCTION: AcpiDmIsUnicodeBuffer
*
* PARAMETERS: Op - Buffer Object to be examined
*
* RETURN: TRUE if buffer contains a UNICODE string
*
* DESCRIPTION: Determine if a buffer Op contains a Unicode string
*
******************************************************************************/
{
UINT32 i;
/* Buffer size is the buffer argument */
/* Next, the initializer byte list to examine */
if (!NextOp)
{
return (FALSE);
}
/* Extract the byte list info */
/*
* Unicode string must have an even number of bytes and last
* word must be zero
*/
if ((!ByteCount) ||
(ByteCount < 4) ||
(ByteCount & 1) ||
{
return (FALSE);
}
/* For each word, 1st byte must be ascii (1-0x7F), 2nd byte must be zero */
{
if ((ByteData[i] == 0) ||
(ByteData[i] > 0x7F) ||
{
return (FALSE);
}
}
/* Ignore the Size argument in the disassembly of this buffer op */
return (TRUE);
}
/*******************************************************************************
*
* FUNCTION: AcpiDmIsStringBuffer
*
* PARAMETERS: Op - Buffer Object to be examined
*
* RETURN: TRUE if buffer contains a ASCII string, FALSE otherwise
*
* DESCRIPTION: Determine if a buffer Op contains a ASCII string
*
******************************************************************************/
{
UINT32 i;
/* Buffer size is the buffer argument */
/* Next, the initializer byte list to examine */
if (!NextOp)
{
return (FALSE);
}
/* Extract the byte list info */
/* Last byte must be the null terminator */
if ((!ByteCount) ||
(ByteCount < 2) ||
{
return (FALSE);
}
for (i = 0; i < (ByteCount - 1); i++)
{
/* TBD: allow some escapes (non-ascii chars).
* they will be handled in the string output routine
*/
{
return (FALSE);
}
}
return (TRUE);
}
/*******************************************************************************
*
* FUNCTION: AcpiDmIsPldBuffer
*
* PARAMETERS: Op - Buffer Object to be examined
*
* RETURN: TRUE if buffer contains a ASCII string, FALSE otherwise
*
* DESCRIPTION: Determine if a buffer Op contains a _PLD structure
*
******************************************************************************/
{
/* Buffer size is the buffer argument */
if (!ParentOp)
{
return (FALSE);
}
/* Check for form: Name(_PLD, Buffer() {}). Not legal, however */
{
{
/* Ignore the Size argument in the disassembly of this buffer op */
return (TRUE);
}
return (FALSE);
}
/* Check for proper form: Name(_PLD, Package() {Buffer() {}}) */
{
if (!ParentOp)
{
return (FALSE);
}
{
{
/* Ignore the Size argument in the disassembly of this buffer op */
return (TRUE);
}
}
}
return (FALSE);
}
/*******************************************************************************
*
* FUNCTION: AcpiDmFindNameByIndex
*
* PARAMETERS: Index - Index of array to check
* List - Array to reference
*
* RETURN: String from List or empty string
*
* DESCRIPTION: Finds and returns the char string located at the given index
* position in List.
*
******************************************************************************/
static const char *
const char **List)
{
const char *NameString;
UINT32 i;
/* Bounds check */
NameString = List[0];
i = 0;
while (NameString)
{
i++;
NameString = List[i];
}
if (Index >= i)
{
/* TBD: Add error msg */
return ("");
}
}
/*******************************************************************************
*
* FUNCTION: AcpiDmPldBuffer
*
* PARAMETERS: Level - Current source code indentation level
* ByteData - Pointer to the byte list
* ByteCount - Length of the byte list
*
* RETURN: None
*
* DESCRIPTION: Dump and format the contents of a _PLD buffer object
*
******************************************************************************/
static void
{
/* Check for valid byte count */
{
return;
}
/* Convert _PLD buffer to local _PLD struct */
if (ACPI_FAILURE (Status))
{
return;
}
AcpiOsPrintf ("\n");
/* First 32-bit dword */
/* Second 32-bit dword */
/* Third 32-bit dword */
/* Fourth 32-bit dword */
if (ByteCount >= ACPI_PLD_REV2_BUFFER_SIZE)
{
/* Fifth 32-bit dword */
}
else /* Rev 1 buffer */
{
}
}
/*******************************************************************************
*
* FUNCTION: AcpiDmUnicode
*
* PARAMETERS: Op - Byte List op containing Unicode string
*
* RETURN: None
*
* DESCRIPTION: Dump Unicode string as a standard ASCII string. (Remove
* the extra zero bytes).
*
******************************************************************************/
static void
{
UINT32 i;
int OutputValue;
/* Extract the buffer info as a WORD buffer */
/* Write every other byte as an ASCII character */
AcpiOsPrintf ("\"");
for (i = 0; i < (WordCount - 1); i++)
{
OutputValue = (int) WordData[i];
/* Handle values that must be escaped */
if ((OutputValue == '\"') ||
(OutputValue == '\\'))
{
}
else if (!isprint (OutputValue))
{
}
else
{
}
}
AcpiOsPrintf ("\")");
}
/*******************************************************************************
*
* FUNCTION: AcpiDmGetHardwareIdType
*
* PARAMETERS: Op - Op to be examined
*
* RETURN: None
*
* DESCRIPTION: Determine the type of the argument to a _HID or _CID
* 1) Strings are allowed
* 2) If Integer, determine if it is a valid EISAID
*
******************************************************************************/
static void
{
UINT32 i;
{
case AML_STRING_OP:
/* Mark this string as an _HID/_CID string */
break;
case AML_WORD_OP:
case AML_DWORD_OP:
/* Swap from little-endian to big-endian to simplify conversion */
/* Create the 3 leading ASCII letters */
/* Verify that all 3 are ascii and alpha */
for (i = 0; i < 3; i++)
{
if (!ACPI_IS_ASCII (Prefix[i]) ||
{
return;
}
}
/* Mark this node as convertable to an EISA ID string */
break;
default:
break;
}
}
/*******************************************************************************
*
* FUNCTION: AcpiDmCheckForHardwareId
*
* PARAMETERS: Op - Op to be examined
*
* RETURN: None
*
* DESCRIPTION: Determine if a Name() Op is a _HID/_CID.
*
******************************************************************************/
void
{
/* Get the NameSegment */
if (!Name)
{
return;
}
if (!NextOp)
{
return;
}
/* Check for _HID - has one argument */
{
return;
}
/* Exit if not _CID */
{
return;
}
/* _CID can contain a single argument or a package */
{
return;
}
/* _CID with Package: get the package length, check all elements */
if (!NextOp)
{
return;
}
/* Don't need to use the length, just walk the peer list */
while (NextOp)
{
}
}
/*******************************************************************************
*
* FUNCTION: AcpiDmDecompressEisaId
*
* PARAMETERS: EncodedId - Raw encoded EISA ID.
*
* RETURN: None
*
* DESCRIPTION: Convert an encoded EISAID back to the original ASCII String
* and emit the correct ASL statement. If the ID is known, emit
* a description of the ID as a comment.
*
******************************************************************************/
void
{
/* Convert EISAID to a string an emit the statement */
/* If we know about the ID, emit the description */
if (Info)
{
}
}