dbexec.c revision 26f3cdf03f1adcc98f6d3d99843ee71e9229a8c0
/*******************************************************************************
*
* Module Name: dbexec - debugger control method execution
*
******************************************************************************/
/*
* Copyright (C) 2000 - 2011, 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 "acdebug.h"
#include "acnamesp.h"
#ifdef ACPI_DEBUGGER
#define _COMPONENT ACPI_CA_DEBUGGER
ACPI_MODULE_NAME ("dbexec")
#define DB_DEFAULT_PKG_ELEMENTS 33
/* Local prototypes */
static ACPI_STATUS
static void
static UINT32
void);
static void ACPI_SYSTEM_XFACE
void *Context);
static ACPI_STATUS
void *Context,
void **ReturnValue);
static ACPI_STATUS
int HexChar,
UINT8 *ReturnValue);
static ACPI_STATUS
char *String,
static ACPI_STATUS
char *String,
static void
/*******************************************************************************
*
* FUNCTION: AcpiDbHexCharToValue
*
* PARAMETERS: HexChar - Ascii Hex digit, 0-9|a-f|A-F
* ReturnValue - Where the converted value is returned
*
* RETURN: Status
*
* DESCRIPTION: Convert a single hex character to a 4-bit number (0-16).
*
******************************************************************************/
static ACPI_STATUS
int HexChar,
{
/* Digit must be ascii [0-9a-fA-F] */
if (!ACPI_IS_XDIGIT (HexChar))
{
return (AE_BAD_HEX_CONSTANT);
}
if (HexChar <= 0x39)
{
}
else
{
}
*ReturnValue = Value;
return (AE_OK);
}
/*******************************************************************************
*
* FUNCTION: AcpiDbHexByteToBinary
*
* PARAMETERS: HexByte - Double hex digit (0x00 - 0xFF) in format:
* HiByte then LoByte.
* ReturnValue - Where the converted value is returned
*
* RETURN: Status
*
* DESCRIPTION: Convert two hex characters to an 8 bit number (0 - 255).
*
******************************************************************************/
static ACPI_STATUS
char *HexByte,
{
/* High byte */
if (ACPI_FAILURE (Status))
{
return (Status);
}
/* Low byte */
if (ACPI_FAILURE (Status))
{
return (Status);
}
return (AE_OK);
}
/*******************************************************************************
*
* FUNCTION: AcpiDbConvertToBuffer
*
* PARAMETERS: String - Input string to be converted
* Object - Where the buffer object is returned
*
* RETURN: Status
*
* DESCRIPTION: Convert a string to a buffer object. String is treated a list
* of buffer elements, each separated by a space or comma.
*
******************************************************************************/
static ACPI_STATUS
char *String,
{
UINT32 i;
UINT32 j;
/* Generate the final buffer length */
{
i+=2;
Length++;
while (String[i] &&
{
i++;
}
}
if (!Buffer)
{
return (AE_NO_MEMORY);
}
/* Convert the command line bytes to the buffer */
for (i = 0, j = 0; String[i];)
{
if (ACPI_FAILURE (Status))
{
return (Status);
}
j++;
i+=2;
while (String[i] &&
{
i++;
}
}
return (AE_OK);
}
/*******************************************************************************
*
* FUNCTION: AcpiDbConvertToPackage
*
* PARAMETERS: String - Input string to be converted
* Object - Where the package object is returned
*
* RETURN: Status
*
* DESCRIPTION: Convert a string to a package object. Handles nested packages
* via recursion with AcpiDbConvertToObject.
*
******************************************************************************/
static ACPI_STATUS
char *String,
{
char *This;
char *Next;
UINT32 i;
DB_DEFAULT_PKG_ELEMENTS * sizeof (ACPI_OBJECT));
for (i = 0; i < (DB_DEFAULT_PKG_ELEMENTS - 1); i++)
{
if (!This)
{
break;
}
/* Recursive call to convert each package element */
if (ACPI_FAILURE (Status))
{
return (Status);
}
}
return (AE_OK);
}
/*******************************************************************************
*
* FUNCTION: AcpiDbConvertToObject
*
* PARAMETERS: Type - Object type as determined by parser
* String - Input string to be converted
* Object - Where the new object is returned
*
* RETURN: Status
*
* DESCRIPTION: Convert a typed and tokenized string to an ACPI_OBJECT. Typing:
* 1) String objects were surrounded by quotes.
* 2) Buffer objects were surrounded by parentheses.
* 3) Package objects were surrounded by brackets "[]".
* 4) All standalone tokens are treated as integers.
*
******************************************************************************/
static ACPI_STATUS
char *String,
{
switch (Type)
{
case ACPI_TYPE_STRING:
break;
case ACPI_TYPE_BUFFER:
break;
case ACPI_TYPE_PACKAGE:
break;
default:
break;
}
return (Status);
}
/*******************************************************************************
*
* FUNCTION: AcpiDbDeleteObjects
*
* PARAMETERS: Count - Count of objects in the list
* Objects - Array of ACPI_OBJECTs to be deleted
*
* RETURN: None
*
* DESCRIPTION: Delete a list of ACPI_OBJECTS. Handles packages and nested
* packages via recursion.
*
******************************************************************************/
static void
{
UINT32 i;
for (i = 0; i < Count; i++)
{
{
case ACPI_TYPE_BUFFER:
break;
case ACPI_TYPE_PACKAGE:
/* Recursive call to delete package elements */
/* Free the elements array */
break;
default:
break;
}
}
}
/*******************************************************************************
*
* FUNCTION: AcpiDbExecuteMethod
*
* PARAMETERS: Info - Valid info segment
* ReturnObj - Where to put return object
*
* RETURN: Status
*
* DESCRIPTION: Execute a control method.
*
******************************************************************************/
static ACPI_STATUS
{
UINT32 i;
if (AcpiGbl_DbOutputToFile && !AcpiDbgLevel)
{
AcpiOsPrintf ("Warning: debug output is not enabled!\n");
}
/* Get the NS node, determines existence also */
if (ACPI_FAILURE (Status))
{
}
/* Get the object info for number of method parameters */
if (ACPI_FAILURE (Status))
{
}
ParamObjects.Count = 0;
{
/* Are there arguments to the method? */
i = 0;
{
/* Get arguments passed on the command line */
(i < ACPI_METHOD_NUM_ARGS) &&
(i < ObjInfo->ParamCount);
i++)
{
/* Convert input string (token) to an actual ACPI_OBJECT */
if (ACPI_FAILURE (Status))
{
"While parsing method arguments"));
goto Cleanup;
}
}
}
/* Create additional "default" parameters as needed */
if (i < ObjInfo->ParamCount)
{
AcpiOsPrintf ("Adding %u arguments containing default values\n",
ObjInfo->ParamCount - i);
for (; i < ObjInfo->ParamCount; i++)
{
switch (i)
{
case 0:
break;
case 1:
break;
default:
break;
}
}
}
}
/* Prepare for a return object of arbitrary size */
/* Do the actual method execution */
if (ACPI_FAILURE (Status))
{
if (Status == AE_BUFFER_OVERFLOW)
{
"Possible overflow of internal debugger buffer (size 0x%X needed 0x%X)",
}
}
}
/*******************************************************************************
*
* FUNCTION: AcpiDbExecuteSetup
*
* PARAMETERS: Info - Valid method info
*
* RETURN: None
*
* DESCRIPTION: Setup info segment prior to method execution
*
******************************************************************************/
static void
{
/* Catenate the current scope to the supplied name */
{
}
{
}
else
{
/* No single step, allow redirection to a file */
}
}
#ifdef ACPI_DBG_TRACK_ALLOCATIONS
{
}
#endif
/*******************************************************************************
*
* FUNCTION: AcpiDbGetOutstandingAllocations
*
* PARAMETERS: None
*
* RETURN: Current global allocation count minus cache entries
*
* DESCRIPTION: Determine the current number of "outstanding" allocations --
* those allocations that have not been freed and also are not
* in one of the various object caches.
*
******************************************************************************/
static UINT32
void)
{
UINT32 Outstanding = 0;
#ifdef ACPI_DBG_TRACK_ALLOCATIONS
#endif
return (Outstanding);
}
/*******************************************************************************
*
* FUNCTION: AcpiDbExecutionWalk
*
* PARAMETERS: WALK_CALLBACK
*
* RETURN: Status
*
* DESCRIPTION: Execute a control method. Name is relative to the current
* scope.
*
******************************************************************************/
static ACPI_STATUS
void *Context,
void **ReturnValue)
{
{
return (AE_OK);
}
/* Do the actual method execution */
AcpiOsPrintf ("\n");
return (AE_OK);
}
/*******************************************************************************
*
* FUNCTION: AcpiDbExecute
*
* PARAMETERS: Name - Name of method to execute
* Args - Parameters to the method
*
* RETURN: None
*
* DESCRIPTION: Execute a control method. Name is relative to the current
* scope.
*
******************************************************************************/
void
char *Name,
char **Args,
{
char *NameString;
#ifdef ACPI_DEBUG_OUTPUT
/* Memory allocation tracking */
#endif
if (*Name == '*')
{
return;
}
else
{
if (!NameString)
{
return;
}
}
/*
* Allow any handlers in separate threads to complete.
* (Such as Notify handlers invoked from AML executed above).
*/
#ifdef ACPI_DEBUG_OUTPUT
/* Memory allocation tracking */
if (Allocations > 0)
{
AcpiOsPrintf ("Outstanding: 0x%X allocations after execution\n",
}
#endif
if (ACPI_FAILURE (Status))
{
AcpiOsPrintf ("Execution of %s failed with status %s\n",
}
else
{
/* Display a return object, if any */
{
AcpiOsPrintf ("Execution of %s returned object %p Buflen %X\n",
}
else
{
AcpiOsPrintf ("No return object from execution of %s\n",
}
}
}
/*******************************************************************************
*
* FUNCTION: AcpiDbMethodThread
*
* PARAMETERS: Context - Execution info segment
*
* RETURN: None
*
* DESCRIPTION: Debugger execute thread. Waits for a command line, then
* simply dispatches it.
*
******************************************************************************/
static void ACPI_SYSTEM_XFACE
void *Context)
{
UINT32 i;
/*
* AcpiGbl_DbMethodInfo.Arguments will be passed as method arguments.
* Prevent AcpiGbl_DbMethodInfo from being modified by multiple threads
* concurrently.
*
* Note: The arguments we are passing are used by the ASL test suite
* (aslts). Do not change them without updating the tests.
*/
{
}
{
}
{
if (ACPI_FAILURE (Status))
{
AcpiOsPrintf ("%s During execution of %s at iteration %X\n",
if (Status == AE_ABORT_METHOD)
{
break;
}
}
#if 0
if ((i % 100) == 0)
{
}
{
AcpiOsPrintf ("Execution of %s returned object %p Buflen %X\n",
}
#endif
}
/* Signal our completion */
Allow = 0;
Info->NumCompleted++;
{
/* Do signal for main thread once only */
Allow = 1;
}
if (Allow)
{
if (ACPI_FAILURE (Status))
{
AcpiOsPrintf ("Could not signal debugger thread sync semaphore, %s\n",
}
}
}
/*******************************************************************************
*
* FUNCTION: AcpiDbCreateExecutionThreads
*
* PARAMETERS: NumThreadsArg - Number of threads to create
* NumLoopsArg - Loop count for the thread(s)
* MethodNameArg - Control method to execute
*
* RETURN: None
*
* DESCRIPTION: Create threads to execute method(s)
*
******************************************************************************/
void
char *NumThreadsArg,
char *NumLoopsArg,
char *MethodNameArg)
{
UINT32 i;
/* Get the arguments */
if (!NumThreads || !NumLoops)
{
AcpiOsPrintf ("Bad argument: Threads %X, Loops %X\n",
return;
}
/*
* Create the semaphore for synchronization of
* the created threads with the main thread.
*/
if (ACPI_FAILURE (Status))
{
AcpiOsPrintf ("Could not create semaphore for synchronization with the main thread, %s\n",
return;
}
/*
* Create the semaphore for synchronization
* between the created threads.
*/
if (ACPI_FAILURE (Status))
{
AcpiOsPrintf ("Could not create semaphore for synchronization between the created threads, %s\n",
(void) AcpiOsDeleteSemaphore (MainThreadGate);
return;
}
if (ACPI_FAILURE (Status))
{
AcpiOsPrintf ("Could not create semaphore for synchronization of AcpiGbl_DbMethodInfo, %s\n",
(void) AcpiOsDeleteSemaphore (ThreadCompleteGate);
(void) AcpiOsDeleteSemaphore (MainThreadGate);
return;
}
/* Array to store IDs of threads */
{
AcpiOsPrintf ("No memory for thread IDs array\n");
(void) AcpiOsDeleteSemaphore (MainThreadGate);
(void) AcpiOsDeleteSemaphore (ThreadCompleteGate);
(void) AcpiOsDeleteSemaphore (InfoGate);
return;
}
/* Setup the context to be passed to each thread */
/* Init arguments to be passed to method */
/* Create the threads */
AcpiOsPrintf ("Creating %X threads to execute %X times each\n",
for (i = 0; i < (NumThreads); i++)
{
if (ACPI_FAILURE (Status))
{
break;
}
}
/* Wait for all threads to complete */
/* Cleanup and exit */
(void) AcpiOsDeleteSemaphore (MainThreadGate);
(void) AcpiOsDeleteSemaphore (ThreadCompleteGate);
(void) AcpiOsDeleteSemaphore (InfoGate);
}
#endif /* ACPI_DEBUGGER */