const char *acpi_ut_scan_number(const char *string, u64 *number_ptr) { u64 number = 0; while (ACPI_IS_DIGIT(*string)) { number *= 10; number += *(string++) - '0'; } *number_ptr = number; return (string); }
const char * AcpiUtScanNumber ( const char *String, UINT64 *NumberPtr) { UINT64 Number = 0; while (ACPI_IS_DIGIT (*String)) { Number *= 10; Number += *(String++) - '0'; } *NumberPtr = Number; return (String); }
int acpi_ut_vsnprintf(char *string, acpi_size size, const char *format, va_list args) { u8 base = 10; u8 type = 0; s32 width = -1; s32 precision = -1; char qualifier = 0; u64 number; char *pos; char *end; char c; const char *s; const void *p; s32 length; int i; pos = string; end = string + size; for (; *format; ++format) { if (*format != '%') { pos = acpi_ut_bound_string_output(pos, end, *format); continue; } /* Process sign */ do { ++format; if (*format == '#') { type |= ACPI_FORMAT_PREFIX; } else if (*format == '0') { type |= ACPI_FORMAT_ZERO; } else if (*format == '+') { type |= ACPI_FORMAT_SIGN_PLUS; } else if (*format == ' ') { type |= ACPI_FORMAT_SIGN_PLUS_SPACE; } else if (*format == '-') { type |= ACPI_FORMAT_LEFT; } else { break; } } while (1); /* Process width */ width = -1; if (ACPI_IS_DIGIT(*format)) { format = acpi_ut_scan_number(format, &number); width = (s32) number; } else if (*format == '*') { ++format; width = va_arg(args, int); if (width < 0) { width = -width; type |= ACPI_FORMAT_LEFT; } } /* Process precision */ precision = -1; if (*format == '.') { ++format; if (ACPI_IS_DIGIT(*format)) { format = acpi_ut_scan_number(format, &number); precision = (s32) number; } else if (*format == '*') { ++format; precision = va_arg(args, int); }
UINT32 AcpiUtStrtoul ( const char *String, char **Terminator, UINT32 Base) { UINT32 converted = 0; UINT32 index; UINT32 sign; const char *StringStart; UINT32 ReturnValue = 0; ACPI_STATUS Status = AE_OK; /* * Save the value of the pointer to the buffer's first * character, save the current errno value, and then * skip over any white space in the buffer: */ StringStart = String; while (ACPI_IS_SPACE (*String) || *String == '\t') { ++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 == '-') { sign = NEGATIVE; ++String; } else if (*String == '+') { ++String; sign = POSITIVE; } else { sign = POSITIVE; } /* * 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') { if (AcpiUtToLower (*(++String)) == 'x') { Base = 16; ++String; } else { Base = 8; } } else { Base = 10; } } else if (Base < 2 || Base > 36) { /* * The specified Base parameter is not in the domain of * this function: */ goto done; } /* * For octal and hexadecimal bases, skip over the leading * 0 or 0x, if they are present. */ if (Base == 8 && *String == '0') { String++; } if (Base == 16 && *String == '0' && AcpiUtToLower (*(++String)) == 'x') { String++; } /* * Main loop: convert the string to an unsigned long: */ while (*String) { if (ACPI_IS_DIGIT (*String)) { index = (UINT32) ((UINT8) *String - '0'); } else { index = (UINT32) AcpiUtToUpper (*String); if (ACPI_IS_UPPER (index)) { index = index - 'A' + 10; } else { goto done; } } if (index >= Base) { goto done; } /* * Check to see if value is out of range: */ if (ReturnValue > ((ACPI_UINT32_MAX - (UINT32) index) / (UINT32) Base)) { Status = AE_ERROR; ReturnValue = 0; /* reset */ } else { ReturnValue *= Base; ReturnValue += index; converted = 1; } ++String; } done: /* * If appropriate, update the caller's pointer to the next * unconverted character in the buffer. */ if (Terminator) { if (converted == 0 && ReturnValue == 0 && String != NULL) { *Terminator = (char *) StringStart; } else { *Terminator = (char *) String; } } if (Status == AE_ERROR) { ReturnValue = ACPI_UINT32_MAX; } /* * If a minus sign was present, then "the conversion is negated": */ if (sign == NEGATIVE) { ReturnValue = (ACPI_UINT32_MAX - ReturnValue) + 1; } return (ReturnValue); }
acpi_status acpi_ut_strtoul64(char *string, u32 base, u64 *ret_integer) { u32 this_digit = 0; u64 return_value = 0; u64 quotient; u64 dividend; u32 to_integer_op = (base == ACPI_ANY_BASE); u32 mode32 = (acpi_gbl_integer_byte_width == 4); u8 valid_digits = 0; u8 sign_of0x = 0; u8 term = 0; ACPI_FUNCTION_TRACE_STR(ut_stroul64, string); switch (base) { case ACPI_ANY_BASE: case 16: break; default: /* Invalid Base */ return_ACPI_STATUS(AE_BAD_PARAMETER); } if (!string) { goto error_exit; } /* Skip over any white space in the buffer */ while ((*string) && (ACPI_IS_SPACE(*string) || *string == '\t')) { string++; } if (to_integer_op) { /* * Base equal to ACPI_ANY_BASE means 'ToInteger operation case'. * We need to determine if it is decimal or hexadecimal. */ if ((*string == '0') && (ACPI_TOLOWER(*(string + 1)) == 'x')) { sign_of0x = 1; base = 16; /* Skip over the leading '0x' */ string += 2; } else { base = 10; } } /* Any string left? Check that '0x' is not followed by white space. */ if (!(*string) || ACPI_IS_SPACE(*string) || *string == '\t') { if (to_integer_op) { goto error_exit; } else { goto all_done; } } /* * Perform a 32-bit or 64-bit conversion, depending upon the current * execution mode of the interpreter */ dividend = (mode32) ? ACPI_UINT32_MAX : ACPI_UINT64_MAX; /* Main loop: convert the string to a 32- or 64-bit integer */ while (*string) { if (ACPI_IS_DIGIT(*string)) { /* Convert ASCII 0-9 to Decimal value */ this_digit = ((u8)*string) - '0'; } else if (base == 10) { /* Digit is out of range; possible in to_integer case only */ term = 1; } else { this_digit = (u8)ACPI_TOUPPER(*string); if (ACPI_IS_XDIGIT((char)this_digit)) { /* Convert ASCII Hex char to value */ this_digit = this_digit - 'A' + 10; } else { term = 1; } } if (term) { if (to_integer_op) { goto error_exit; } else { break; } } else if ((valid_digits == 0) && (this_digit == 0) && !sign_of0x) { /* Skip zeros */ string++; continue; } valid_digits++; if (sign_of0x && ((valid_digits > 16) || ((valid_digits > 8) && mode32))) { /* * This is to_integer operation case. * No any restrictions for string-to-integer conversion, * see ACPI spec. */ goto error_exit; } /* Divide the digit into the correct position */ (void)acpi_ut_short_divide((dividend - (u64)this_digit), base, "ient, NULL); if (return_value > quotient) { if (to_integer_op) { goto error_exit; } else { break; } } return_value *= base; return_value += this_digit; string++; } /* All done, normal exit */ all_done: ACPI_DEBUG_PRINT((ACPI_DB_EXEC, "Converted value: %8.8X%8.8X\n", ACPI_FORMAT_UINT64(return_value))); *ret_integer = return_value; return_ACPI_STATUS(AE_OK); error_exit: /* Base was set/validated above */ if (base == 10) { return_ACPI_STATUS(AE_BAD_DECIMAL_CONSTANT); } else { return_ACPI_STATUS(AE_BAD_HEX_CONSTANT); } }
ACPI_STATUS AcpiUtStrtoul64 ( char *String, UINT32 Base, 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; ACPI_FUNCTION_TRACE_STR (UtStroul64, String); switch (Base) { case ACPI_ANY_BASE: case 16: break; default: /* Invalid Base */ return_ACPI_STATUS (AE_BAD_PARAMETER); } if (!String) { goto ErrorExit; } /* Skip over any white space in the buffer */ while ((*String) && (ACPI_IS_SPACE (*String) || *String == '\t')) { String++; } if (ToIntegerOp) { /* * Base equal to ACPI_ANY_BASE means 'ToInteger operation case'. * We need to determine if it is decimal or hexadecimal. */ if ((*String == '0') && (ACPI_TOLOWER (*(String + 1)) == 'x')) { SignOf0x = 1; Base = 16; /* Skip over the leading '0x' */ String += 2; } else { Base = 10; } } /* Any string left? Check that '0x' is not followed by white space. */ if (!(*String) || ACPI_IS_SPACE (*String) || *String == '\t') { if (ToIntegerOp) { goto ErrorExit; } else { goto AllDone; } } /* * Perform a 32-bit or 64-bit conversion, depending upon the current * execution mode of the interpreter */ Dividend = (Mode32) ? ACPI_UINT32_MAX : ACPI_UINT64_MAX; /* Main loop: convert the string to a 32- or 64-bit integer */ while (*String) { if (ACPI_IS_DIGIT (*String)) { /* Convert ASCII 0-9 to Decimal value */ ThisDigit = ((UINT8) *String) - '0'; } else if (Base == 10) { /* Digit is out of range; possible in ToInteger case only */ Term = 1; } else { ThisDigit = (UINT8) ACPI_TOUPPER (*String); if (ACPI_IS_XDIGIT ((char) ThisDigit)) { /* Convert ASCII Hex char to value */ ThisDigit = ThisDigit - 'A' + 10; } else { Term = 1; } } if (Term) { if (ToIntegerOp) { goto ErrorExit; } else { break; } } else if ((ValidDigits == 0) && (ThisDigit == 0) && !SignOf0x) { /* Skip zeros */ String++; continue; } ValidDigits++; if (SignOf0x && ((ValidDigits > 16) || ((ValidDigits > 8) && Mode32))) { /* * This is ToInteger operation case. * No any restrictions for string-to-integer conversion, * see ACPI spec. */ goto ErrorExit; } /* Divide the digit into the correct position */ (void) AcpiUtShortDivide ((Dividend - (UINT64) ThisDigit), Base, &Quotient, NULL); if (ReturnValue > Quotient) { if (ToIntegerOp) { goto ErrorExit; } else { break; } } ReturnValue *= Base; ReturnValue += ThisDigit; String++; } /* All done, normal exit */ AllDone: ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "Converted value: %8.8X%8.8X\n", ACPI_FORMAT_UINT64 (ReturnValue))); *RetInteger = ReturnValue; return_ACPI_STATUS (AE_OK); ErrorExit: /* Base was set/validated above */ if (Base == 10) { return_ACPI_STATUS (AE_BAD_DECIMAL_CONSTANT); } else { return_ACPI_STATUS (AE_BAD_HEX_CONSTANT); } }
void AcpiDmPredefinedDescription ( ACPI_PARSE_OBJECT *Op) { #ifdef ACPI_ASL_COMPILER const AH_PREDEFINED_NAME *Info; char *NameString; int LastCharIsDigit; int LastCharsAreHex; if (!Op) { return; } /* Ensure that the comment field is emitted only once */ if (Op->Common.DisasmFlags & ACPI_PARSEOP_PREDEF_CHECKED) { return; } Op->Common.DisasmFlags |= ACPI_PARSEOP_PREDEF_CHECKED; /* Predefined name must start with an underscore */ NameString = ACPI_CAST_PTR (char, &Op->Named.Name); if (NameString[0] != '_') { return; } /* * Check for the special ACPI names: * _ACd, _ALd, _EJd, _Exx, _Lxx, _Qxx, _Wxx, _T_a * (where d=decimal_digit, x=hex_digit, a=anything) * * Convert these to the generic name for table lookup. * Note: NameString is guaranteed to be upper case here. */ LastCharIsDigit = (ACPI_IS_DIGIT (NameString[3])); /* d */ LastCharsAreHex = (ACPI_IS_XDIGIT (NameString[2]) && /* xx */ ACPI_IS_XDIGIT (NameString[3])); switch (NameString[1]) { case 'A': if ((NameString[2] == 'C') && (LastCharIsDigit)) { NameString = "_ACx"; } else if ((NameString[2] == 'L') && (LastCharIsDigit)) { NameString = "_ALx"; } break; case 'E': if ((NameString[2] == 'J') && (LastCharIsDigit)) { NameString = "_EJx"; } else if (LastCharsAreHex) { NameString = "_Exx"; } break; case 'L': if (LastCharsAreHex) { NameString = "_Lxx"; } break; case 'Q': if (LastCharsAreHex) { NameString = "_Qxx"; } break; case 'T': if (NameString[2] == '_') { NameString = "_T_x"; } break; case 'W': if (LastCharsAreHex) { NameString = "_Wxx"; } break; default: break; } /* Match the name in the info table */ for (Info = AslPredefinedInfo; Info->Name; Info++) { if (ACPI_COMPARE_NAME (NameString, Info->Name)) { AcpiOsPrintf (" // %4.4s: %s", NameString, ACPI_CAST_PTR (char, Info->Description)); return; } }
ACPI_STATUS DtStrtoul64 ( char *String, UINT64 *ReturnInteger) { char *ThisChar = String; UINT32 ThisDigit; UINT64 ReturnValue = 0; int DigitCount = 0; /* Skip over any white space in the buffer */ while ((*ThisChar == ' ') || (*ThisChar == '\t')) { ThisChar++; } /* Skip leading zeros */ while ((*ThisChar) == '0') { ThisChar++; } /* Convert character-by-character */ while (*ThisChar) { if (ACPI_IS_DIGIT (*ThisChar)) { /* Convert ASCII 0-9 to Decimal value */ ThisDigit = ((UINT8) *ThisChar) - '0'; } else /* Letter */ { ThisDigit = (UINT32) ACPI_TOUPPER (*ThisChar); if (!ACPI_IS_XDIGIT ((char) ThisDigit)) { /* Not A-F */ return (AE_BAD_CHARACTER); } /* Convert ASCII Hex char (A-F) to value */ ThisDigit = (ThisDigit - 'A') + 10; } /* Insert the 4-bit hex digit */ ReturnValue <<= 4; ReturnValue += ThisDigit; ThisChar++; DigitCount++; if (DigitCount > 16) { /* Value is too large (> 64 bits/8 bytes/16 hex digits) */ return (AE_LIMIT); } } *ReturnInteger = ReturnValue; return (AE_OK); }
acpi_status acpi_ut_strtoul64 ( char *string, u32 base, acpi_integer *ret_integer) { u32 this_digit = 0; acpi_integer return_value = 0; acpi_integer quotient; ACPI_FUNCTION_TRACE ("ut_stroul64"); if ((!string) || !(*string)) { goto error_exit; } switch (base) { case ACPI_ANY_BASE: case 10: case 16: break; default: /* Invalid Base */ return_ACPI_STATUS (AE_BAD_PARAMETER); } /* Skip over any white space in the buffer */ while (ACPI_IS_SPACE (*string) || *string == '\t') { string++; } /* * If the input parameter Base is zero, then we need to * determine if it is decimal or hexadecimal: */ if (base == 0) { if ((*string == '0') && (ACPI_TOLOWER (*(string + 1)) == 'x')) { base = 16; string += 2; } else { base = 10; } } /* * For hexadecimal base, skip over the leading * 0 or 0x, if they are present. */ if ((base == 16) && (*string == '0') && (ACPI_TOLOWER (*(string + 1)) == 'x')) { string += 2; } /* Any string left? */ if (!(*string)) { goto error_exit; } /* Main loop: convert the string to a 64-bit integer */ while (*string) { if (ACPI_IS_DIGIT (*string)) { /* Convert ASCII 0-9 to Decimal value */ this_digit = ((u8) *string) - '0'; } else { if (base == 10) { /* Digit is out of range */ goto error_exit; } this_digit = (u8) ACPI_TOUPPER (*string); if (ACPI_IS_XDIGIT ((char) this_digit)) { /* Convert ASCII Hex char to value */ this_digit = this_digit - 'A' + 10; } else { /* * We allow non-hex chars, just stop now, same as end-of-string. * See ACPI spec, string-to-integer conversion. */ break; } } /* Divide the digit into the correct position */ (void) acpi_ut_short_divide ((ACPI_INTEGER_MAX - (acpi_integer) this_digit), base, "ient, NULL); if (return_value > quotient) { goto error_exit; } return_value *= base; return_value += this_digit; string++; } /* All done, normal exit */ *ret_integer = return_value; return_ACPI_STATUS (AE_OK); error_exit: /* Base was set/validated above */ if (base == 10) { return_ACPI_STATUS (AE_BAD_DECIMAL_CONSTANT); } else { return_ACPI_STATUS (AE_BAD_HEX_CONSTANT); } }
int AcpiUtVsnprintf ( char *String, ACPI_SIZE Size, const char *Format, va_list Args) { UINT8 Base = 10; UINT8 Type = 0; INT32 Width = -1; INT32 Precision = -1; char Qualifier = 0; UINT64 Number; char *Pos; char *End; char c; const char *s; const void *p; INT32 Length; int i; Pos = String; End = String + Size; for (; *Format; ++Format) { if (*Format != '%') { Pos = AcpiUtBoundStringOutput (Pos, End, *Format); continue; } /* Process sign */ do { ++Format; if (*Format == '#') { Type |= ACPI_FORMAT_PREFIX; } else if (*Format == '0') { Type |= ACPI_FORMAT_ZERO; } else if (*Format == '+') { Type |= ACPI_FORMAT_SIGN_PLUS; } else if (*Format == ' ') { Type |= ACPI_FORMAT_SIGN_PLUS_SPACE; } else if (*Format == '-') { Type |= ACPI_FORMAT_LEFT; } else { break; } } while (1); /* Process width */ Width = -1; if (ACPI_IS_DIGIT (*Format)) { Format = AcpiUtScanNumber (Format, &Number); Width = (INT32) Number; } else if (*Format == '*') { ++Format; Width = va_arg (Args, int); if (Width < 0) { Width = -Width; Type |= ACPI_FORMAT_LEFT; } } /* Process precision */ Precision = -1; if (*Format == '.') { ++Format; if (ACPI_IS_DIGIT(*Format)) { Format = AcpiUtScanNumber (Format, &Number); Precision = (INT32) Number; } else if (*Format == '*') { ++Format; Precision = va_arg (Args, int); }
ACPI_STATUS AcpiUtStrtoul64 ( char *String, UINT32 Base, ACPI_INTEGER *RetInteger) { UINT32 Index; ACPI_INTEGER ReturnValue = 0; ACPI_STATUS Status = AE_OK; ACPI_INTEGER Dividend; ACPI_INTEGER Quotient; *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: */ while (ACPI_IS_SPACE (*String) || *String == '\t') { ++String; } /* * 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') { if (ACPI_TOLOWER (*(++String)) == 'x') { 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. */ if (Base == 8 && *String == '0') { String++; } if (Base == 16 && *String == '0' && ACPI_TOLOWER (*(++String)) == 'x') { String++; } /* Main loop: convert the string to an unsigned long */ while (*String) { if (ACPI_IS_DIGIT (*String)) { Index = ((UINT8) *String) - '0'; } else { Index = (UINT8) ACPI_TOUPPER (*String); if (ACPI_IS_UPPER ((char) Index)) { Index = Index - 'A' + 10; } else { goto ErrorExit; } } if (Index >= Base) { goto ErrorExit; } /* Check to see if value is out of range: */ Dividend = ACPI_INTEGER_MAX - (ACPI_INTEGER) Index; (void) AcpiUtShortDivide (&Dividend, Base, &Quotient, NULL); if (ReturnValue > Quotient) { goto ErrorExit; } ReturnValue *= Base; ReturnValue += Index; ++String; } *RetInteger = ReturnValue; return (Status); ErrorExit: switch (Base) { case 8: Status = AE_BAD_OCTAL_CONSTANT; break; case 10: Status = AE_BAD_DECIMAL_CONSTANT; break; case 16: Status = AE_BAD_HEX_CONSTANT; break; default: /* Base validated above */ break; } return (Status); }