Skip to content

Commit

Permalink
Utilities: Update for strtoul64 merger
Browse files Browse the repository at this point in the history
Fixes a problem with the merger of the two internal versions
of this function. Make the maximum integer width (32-bit or
64-bit) a parameter to the function so that it no longer
exclusively uses the integer width specified in the DSDT/SSDT.
ACPICA BZ 1260
  • Loading branch information
acpibob committed Mar 8, 2016
1 parent 9838767 commit 795e136
Show file tree
Hide file tree
Showing 12 changed files with 61 additions and 41 deletions.
4 changes: 2 additions & 2 deletions source/compiler/aslmessages.c
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ const char *AslCompilerMsgs [] =
/* ASL_MSG_HID_SUFFIX */ "_HID suffix must be all hex digits",
/* ASL_MSG_INCLUDE_FILE_OPEN */ "Could not open include file",
/* ASL_MSG_INPUT_FILE_OPEN */ "Could not open input file",
/* ASL_MSG_INTEGER_LENGTH */ "64-bit integer in 32-bit table, truncating (DSDT version < 2)",
/* ASL_MSG_INTEGER_LENGTH */ "64-bit integer in 32-bit table, truncating (DSDT or SSDT version < 2)",
/* ASL_MSG_INTEGER_OPTIMIZATION */ "Integer optimized to single-byte AML opcode",
/* ASL_MSG_INTERRUPT_LIST */ "Too many interrupts (16 max)",
/* ASL_MSG_INTERRUPT_NUMBER */ "Invalid interrupt number (must be 0-15)",
Expand Down Expand Up @@ -296,7 +296,7 @@ const char *AslCompilerMsgs [] =
/* ASL_MSG_TAG_SMALLER */ "ResourceTag smaller than Field",
/* ASL_MSG_TIMEOUT */ "Result is not used, possible operator timeout will be missed",
/* ASL_MSG_TOO_MANY_TEMPS */ "Method requires too many temporary variables (_T_x)",
/* ASL_MSG_TRUNCATION */ "64-bit return value will be truncated to 32 bits (DSDT version < 2)",
/* ASL_MSG_TRUNCATION */ "64-bit return value will be truncated to 32 bits (DSDT or SSDT version < 2)",
/* ASL_MSG_UNKNOWN_RESERVED_NAME */ "Unknown reserved name",
/* ASL_MSG_UNREACHABLE_CODE */ "Statement is unreachable",
/* ASL_MSG_UNSUPPORTED */ "Unsupported feature",
Expand Down
4 changes: 3 additions & 1 deletion source/compiler/aslutils.c
Original file line number Diff line number Diff line change
Expand Up @@ -978,7 +978,9 @@ UtDoConstant (
char ErrBuf[64];


Status = AcpiUtStrtoul64 (String, 0, &Converted);
Status = AcpiUtStrtoul64 (String, ACPI_ANY_BASE,
ACPI_MAX64_BYTE_WIDTH, &Converted);

if (ACPI_FAILURE (Status))
{
sprintf (ErrBuf, "%s %s\n", "Conversion error:",
Expand Down
6 changes: 3 additions & 3 deletions source/compiler/dtparser.y
Original file line number Diff line number Diff line change
Expand Up @@ -241,15 +241,15 @@ Expression

/* Default base for a non-prefixed integer is 16 */

| EXPOP_NUMBER { AcpiUtStrtoul64 (DtParsertext, 16, &$$);}
| EXPOP_NUMBER { AcpiUtStrtoul64 (DtParsertext, 16, ACPI_MAX64_BYTE_WIDTH, &$$);}

/* Standard hex number (0x1234) */

| EXPOP_HEX_NUMBER { AcpiUtStrtoul64 (DtParsertext, 16, &$$);}
| EXPOP_HEX_NUMBER { AcpiUtStrtoul64 (DtParsertext, 16, ACPI_MAX64_BYTE_WIDTH, &$$);}

/* TBD: Decimal number with prefix (0d1234) - Not supported by strtoul64 at this time */

| EXPOP_DECIMAL_NUMBER { AcpiUtStrtoul64 (DtParsertext, 10, &$$);}
| EXPOP_DECIMAL_NUMBER { AcpiUtStrtoul64 (DtParsertext, 10, ACPI_MAX64_BYTE_WIDTH, &$$);}
;
%%

Expand Down
4 changes: 2 additions & 2 deletions source/compiler/prparser.y
Original file line number Diff line number Diff line change
Expand Up @@ -254,11 +254,11 @@ Expression

/* Default base for a non-prefixed integer is 10 */

| EXPOP_NUMBER { AcpiUtStrtoul64 (PrParsertext, 10, &$$);}
| EXPOP_NUMBER { AcpiUtStrtoul64 (PrParsertext, 10, ACPI_MAX64_BYTE_WIDTH, &$$);}

/* Standard hex number (0x1234) */

| EXPOP_HEX_NUMBER { AcpiUtStrtoul64 (PrParsertext, 16, &$$);}
| EXPOP_HEX_NUMBER { AcpiUtStrtoul64 (PrParsertext, 16, ACPI_MAX64_BYTE_WIDTH, &$$);}
;
%%

Expand Down
3 changes: 2 additions & 1 deletion source/components/debugger/dbconvert.c
Original file line number Diff line number Diff line change
Expand Up @@ -393,7 +393,8 @@ AcpiDbConvertToObject (
default:

Object->Type = ACPI_TYPE_INTEGER;
Status = AcpiUtStrtoul64 (String, 16, &Object->Integer.Value);
Status = AcpiUtStrtoul64 (String, 16, AcpiGbl_IntegerByteWidth,
&Object->Integer.Value);
break;
}

Expand Down
3 changes: 2 additions & 1 deletion source/components/executer/exconvrt.c
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,8 @@ AcpiExConvertToInteger (
* of ACPI 3.0) is that the ToInteger() operator allows both decimal
* and hexadecimal strings (hex prefixed with "0x").
*/
Status = AcpiUtStrtoul64 ((char *) Pointer, Flags, &Result);
Status = AcpiUtStrtoul64 ((char *) Pointer, Flags,
AcpiGbl_IntegerByteWidth, &Result);
if (ACPI_FAILURE (Status))
{
return_ACPI_STATUS (Status);
Expand Down
2 changes: 1 addition & 1 deletion source/components/namespace/nsconvert.c
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ AcpiNsConvertToInteger (
/* String-to-Integer conversion */

Status = AcpiUtStrtoul64 (OriginalObject->String.Pointer,
ACPI_ANY_BASE, &Value);
ACPI_ANY_BASE, AcpiGbl_IntegerByteWidth, &Value);
if (ACPI_FAILURE (Status))
{
return (Status);
Expand Down
61 changes: 34 additions & 27 deletions source/components/utilities/utnonansi.c
Original file line number Diff line number Diff line change
Expand Up @@ -316,41 +316,44 @@ AcpiUtSafeStrncat (
*
* FUNCTION: AcpiUtStrtoul64
*
* PARAMETERS: String - Null terminated string
* Base - Radix of the string: 16 or ACPI_ANY_BASE;
* ACPI_ANY_BASE means 'in behalf of ToInteger'
* RetInteger - Where the converted integer is returned
* PARAMETERS: String - Null terminated string
* Base - Radix of the string: 16 or 10 or
* ACPI_ANY_BASE
* MaxIntegerByteWidth - Maximum allowable integer,in bytes:
* 4 or 8 (32 or 64 bits)
* RetInteger - Where the converted integer is
* returned
*
* RETURN: Status and Converted value
*
* DESCRIPTION: Convert a string into an unsigned value. Performs either a
* 32-bit or 64-bit conversion, depending on the current mode
* of the interpreter.
* 32-bit or 64-bit conversion, depending on the input integer
* size (often the current mode of the interpreter).
*
* NOTES: AcpiGbl_IntegerByteWidth should be set to the proper width.
* NOTES: Negative numbers are not supported, as they are not supported
* by ACPI.
*
* AcpiGbl_IntegerByteWidth should be set to the proper width.
* For the core ACPICA code, this width depends on the DSDT
* version. For iASL, the default byte width is always 8.
* version. For iASL, the default byte width is always 8 for the
* parser, but error checking is performed later to flag cases
* where a 64-bit constant is defined in a 32-bit DSDT/SSDT.
*
* Does not support Octal strings, not needed at this time.
*
* There is an earlier version of the function after this one,
* below. It is slightly different than this one, and the two
* may eventually may need to be merged. (01/2016).
*
******************************************************************************/

ACPI_STATUS
AcpiUtStrtoul64 (
char *String,
UINT32 Base,
UINT32 MaxIntegerByteWidth,
UINT64 *RetInteger)
{
UINT32 ThisDigit = 0;
UINT64 ReturnValue = 0;
UINT64 Quotient;
UINT64 Dividend;
UINT32 ToIntegerOp = (Base == ACPI_ANY_BASE);
UINT32 Mode32 = (AcpiGbl_IntegerByteWidth == 4);
UINT8 ValidDigits = 0;
UINT8 SignOf0x = 0;
UINT8 Term = 0;
Expand All @@ -362,6 +365,7 @@ AcpiUtStrtoul64 (
switch (Base)
{
case ACPI_ANY_BASE:
case 10:
case 16:

break;
Expand All @@ -385,10 +389,10 @@ AcpiUtStrtoul64 (
String++;
}

if (ToIntegerOp)
if (Base == ACPI_ANY_BASE)
{
/*
* Base equal to ACPI_ANY_BASE means 'ToInteger operation case'.
* Base equal to ACPI_ANY_BASE means 'Either decimal or hex'.
* We need to determine if it is decimal or hexadecimal.
*/
if ((*String == '0') && (tolower ((int) *(String + 1)) == 'x'))
Expand All @@ -409,7 +413,7 @@ AcpiUtStrtoul64 (

if (!(*String) || isspace ((int) *String) || *String == '\t')
{
if (ToIntegerOp)
if (Base == ACPI_ANY_BASE)
{
goto ErrorExit;
}
Expand All @@ -420,10 +424,11 @@ AcpiUtStrtoul64 (
}

/*
* Perform a 32-bit or 64-bit conversion, depending upon the current
* execution mode of the interpreter
* Perform a 32-bit or 64-bit conversion, depending upon the input
* byte width
*/
Dividend = (Mode32) ? ACPI_UINT32_MAX : ACPI_UINT64_MAX;
Dividend = (MaxIntegerByteWidth <= ACPI_MAX32_BYTE_WIDTH) ?
ACPI_UINT32_MAX : ACPI_UINT64_MAX;

/* Main loop: convert the string to a 32- or 64-bit integer */

Expand Down Expand Up @@ -458,7 +463,7 @@ AcpiUtStrtoul64 (

if (Term)
{
if (ToIntegerOp)
if (Base == ACPI_ANY_BASE)
{
goto ErrorExit;
}
Expand All @@ -476,11 +481,12 @@ AcpiUtStrtoul64 (

ValidDigits++;

if (SignOf0x && ((ValidDigits > 16) || ((ValidDigits > 8) && Mode32)))
if (SignOf0x && ((ValidDigits > 16) ||
((ValidDigits > 8) && (MaxIntegerByteWidth <= ACPI_MAX32_BYTE_WIDTH))))
{
/*
* This is ToInteger operation case.
* No any restrictions for string-to-integer conversion,
* No restrictions for string-to-integer conversion,
* see ACPI spec.
*/
goto ErrorExit;
Expand All @@ -493,7 +499,7 @@ AcpiUtStrtoul64 (

if (ReturnValue > Quotient)
{
if (ToIntegerOp)
if (Base == ACPI_ANY_BASE)
{
goto ErrorExit;
}
Expand All @@ -520,7 +526,8 @@ AcpiUtStrtoul64 (


ErrorExit:
/* Base was set/validated above */

/* Base was set/validated above (10 or 16) */

if (Base == 10)
{
Expand All @@ -532,9 +539,9 @@ AcpiUtStrtoul64 (
}
}


#ifdef _OBSOLETE_FUNCTIONS
/* TBD: use version in ACPICA main code base? */
/* DONE: 01/2016 */
/* Removed: 01/2016 */

/*******************************************************************************
*
Expand Down
6 changes: 6 additions & 0 deletions source/include/acutils.h
Original file line number Diff line number Diff line change
Expand Up @@ -266,8 +266,14 @@ ACPI_STATUS
AcpiUtStrtoul64 (
char *String,
UINT32 Base,
UINT32 MaxIntegerByteWidth,
UINT64 *RetInteger);

/* Values for MaxIntegerByteWidth above */

#define ACPI_MAX32_BYTE_WIDTH 4
#define ACPI_MAX64_BYTE_WIDTH 8


/*
* utglobal - Global data structures and procedures
Expand Down
3 changes: 2 additions & 1 deletion source/tools/acpidump/apdump.c
Original file line number Diff line number Diff line change
Expand Up @@ -398,7 +398,8 @@ ApDumpTableByAddress (

/* Convert argument to an integer physical address */

Status = AcpiUtStrtoul64 (AsciiAddress, 0, &LongAddress);
Status = AcpiUtStrtoul64 (AsciiAddress, ACPI_ANY_BASE,
ACPI_MAX64_BYTE_WIDTH, &LongAddress);
if (ACPI_FAILURE (Status))
{
AcpiLogError ("%s: Could not convert to a physical address\n",
Expand Down
3 changes: 2 additions & 1 deletion source/tools/acpidump/apmain.c
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,8 @@ ApDoOptions (

case 'r': /* Dump tables from specified RSDP */

Status = AcpiUtStrtoul64 (AcpiGbl_Optarg, 0, &Gbl_RsdpBase);
Status = AcpiUtStrtoul64 (AcpiGbl_Optarg, ACPI_ANY_BASE,
ACPI_MAX64_BYTE_WIDTH, &Gbl_RsdpBase);
if (ACPI_FAILURE (Status))
{
AcpiLogError ("%s: Could not convert to a physical address\n",
Expand Down
3 changes: 2 additions & 1 deletion source/tools/acpiexec/aeinitfile.c
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,8 @@ AeDoOneOverride (

/* Extract the 64-bit integer */

Status = AcpiUtStrtoul64 (ValueString, 0, &Value);
Status = AcpiUtStrtoul64 (ValueString, ACPI_ANY_BASE,
ACPI_MAX64_BYTE_WIDTH, &Value);
if (ACPI_FAILURE (Status))
{
AcpiOsPrintf ("%s %s\n", ValueString,
Expand Down

0 comments on commit 795e136

Please sign in to comment.