static void AcpiDbExecuteSetup ( ACPI_DB_METHOD_INFO *Info) { /* Catenate the current scope to the supplied name */ Info->Pathname[0] = 0; if ((Info->Name[0] != '\\') && (Info->Name[0] != '/')) { ACPI_STRCAT (Info->Pathname, AcpiGbl_DbScopeBuf); } ACPI_STRCAT (Info->Pathname, Info->Name); AcpiDbPrepNamestring (Info->Pathname); AcpiDbSetOutputDestination (ACPI_DB_DUPLICATE_OUTPUT); AcpiOsPrintf ("Evaluating %s\n", Info->Pathname); if (Info->Flags & EX_SINGLE_STEP) { AcpiGbl_CmSingleStep = TRUE; AcpiDbSetOutputDestination (ACPI_DB_CONSOLE_OUTPUT); } else { /* No single step, allow redirection to a file */ AcpiDbSetOutputDestination (ACPI_DB_REDIRECTABLE_OUTPUT); } }
void AcpiDbSetScope ( char *Name) { ACPI_STATUS Status; ACPI_NAMESPACE_NODE *Node; if (!Name || Name[0] == 0) { AcpiOsPrintf ("Current scope: %s\n", AcpiGbl_DbScopeBuf); return; } AcpiDbPrepNamestring (Name); if (Name[0] == '\\') { /* Validate new scope from the root */ Status = AcpiNsGetNode (AcpiGbl_RootNode, Name, ACPI_NS_NO_UPSEARCH, &Node); if (ACPI_FAILURE (Status)) { goto ErrorExit; } ACPI_STRCPY (AcpiGbl_DbScopeBuf, Name); ACPI_STRCAT (AcpiGbl_DbScopeBuf, "\\"); } else { /* Validate new scope relative to old scope */ Status = AcpiNsGetNode (AcpiGbl_DbScopeNode, Name, ACPI_NS_NO_UPSEARCH, &Node); if (ACPI_FAILURE (Status)) { goto ErrorExit; } ACPI_STRCAT (AcpiGbl_DbScopeBuf, Name); ACPI_STRCAT (AcpiGbl_DbScopeBuf, "\\"); } AcpiGbl_DbScopeNode = Node; AcpiOsPrintf ("New scope: %s\n", AcpiGbl_DbScopeBuf); return; ErrorExit: AcpiOsPrintf ("Could not attach scope: %s, %s\n", Name, AcpiFormatException (Status)); }
void AcpiUtGetExpectedReturnTypes ( char *Buffer, UINT32 ExpectedBtypes) { UINT32 ThisRtype; UINT32 i; UINT32 j; if (!ExpectedBtypes) { ACPI_STRCPY (Buffer, "NONE"); return; } j = 1; Buffer[0] = 0; ThisRtype = ACPI_RTYPE_INTEGER; for (i = 0; i < ACPI_NUM_RTYPES; i++) { /* If one of the expected types, concatenate the name of this type */ if (ExpectedBtypes & ThisRtype) { ACPI_STRCAT (Buffer, &UtRtypeNames[i][j]); j = 0; /* Use name separator from now on */ } ThisRtype <<= 1; /* Next Rtype */ } }
void acpi_ut_get_expected_return_types(char *buffer, u32 expected_btypes) { u32 this_rtype; u32 i; u32 j; if (!expected_btypes) { ACPI_STRCPY(buffer, "NONE"); return; } j = 1; buffer[0] = 0; this_rtype = ACPI_RTYPE_INTEGER; for (i = 0; i < ACPI_NUM_RTYPES; i++) { /* If one of the expected types, concatenate the name of this type */ if (expected_btypes & this_rtype) { ACPI_STRCAT(buffer, &ut_rtype_names[i][j]); j = 0; /* Use name separator from now on */ } this_rtype <<= 1; /* Next Rtype */ } }
u8 acpi_ut_safe_strcat(char *dest, acpi_size dest_size, char *source) { if ((ACPI_STRLEN(dest) + ACPI_STRLEN(source)) >= dest_size) { return (TRUE); } ACPI_STRCAT(dest, source); return (FALSE); }
BOOLEAN AcpiUtSafeStrcat ( char *Dest, ACPI_SIZE DestSize, char *Source) { if ((ACPI_STRLEN (Dest) + ACPI_STRLEN (Source)) >= DestSize) { return (TRUE); } ACPI_STRCAT (Dest, Source); return (FALSE); }
static char * AcpiDmNormalizeParentPrefix ( ACPI_PARSE_OBJECT *Op, char *Path) { ACPI_NAMESPACE_NODE *Node; char *Fullpath; char *ParentPath; ACPI_SIZE Length; UINT32 Index = 0; if (!Op) { return (NULL); } /* Search upwards in the parse tree until we reach the next namespace node */ Op = Op->Common.Parent; while (Op) { if (Op->Common.Node) { break; } Op = Op->Common.Parent; } if (!Op) { return (NULL); } /* * Find the actual parent node for the reference: * Remove all carat prefixes from the input path. * There may be multiple parent prefixes (For example, ^^^M000) */ Node = Op->Common.Node; while (Node && (*Path == (UINT8) AML_PARENT_PREFIX)) { Node = Node->Parent; Path++; } if (!Node) { return (NULL); } /* Get the full pathname for the parent node */ ParentPath = AcpiNsGetExternalPathname (Node); if (!ParentPath) { return (NULL); } Length = (ACPI_STRLEN (ParentPath) + ACPI_STRLEN (Path) + 1); if (ParentPath[1]) { /* * If ParentPath is not just a simple '\', increment the length * for the required dot separator (ParentPath.Path) */ Length++; /* For External() statements, we do not want a leading '\' */ if (*ParentPath == AML_ROOT_PREFIX) { Index = 1; } } Fullpath = ACPI_ALLOCATE_ZEROED (Length); if (!Fullpath) { goto Cleanup; } /* * Concatenate parent fullpath and path. For example, * parent fullpath "\_SB_", Path "^INIT", Fullpath "\_SB_.INIT" * * Copy the parent path */ ACPI_STRCPY (Fullpath, &ParentPath[Index]); /* * Add dot separator * (don't need dot if parent fullpath is a single backslash) */ if (ParentPath[1]) { ACPI_STRCAT (Fullpath, "."); } /* Copy child path (carat parent prefix(es) were skipped above) */ ACPI_STRCAT (Fullpath, Path); Cleanup: ACPI_FREE (ParentPath); return (Fullpath); }
static acpi_status acpi_ex_name_segment(u8 ** in_aml_address, char *name_string) { char *aml_address = (void *)*in_aml_address; acpi_status status = AE_OK; u32 index; char char_buf[5]; ACPI_FUNCTION_TRACE(ex_name_segment); /* */ char_buf[0] = *aml_address; if ('0' <= char_buf[0] && char_buf[0] <= '9') { ACPI_ERROR((AE_INFO, "Invalid leading digit: %c", char_buf[0])); return_ACPI_STATUS(AE_CTRL_PENDING); } ACPI_DEBUG_PRINT((ACPI_DB_LOAD, "Bytes from stream:\n")); for (index = 0; (index < ACPI_NAME_SIZE) && (acpi_ut_valid_acpi_char(*aml_address, 0)); index++) { char_buf[index] = *aml_address++; ACPI_DEBUG_PRINT((ACPI_DB_LOAD, "%c\n", char_buf[index])); } /* */ if (index == 4) { /* */ char_buf[4] = '\0'; if (name_string) { ACPI_STRCAT(name_string, char_buf); ACPI_DEBUG_PRINT((ACPI_DB_NAMES, "Appended to - %s\n", name_string)); } else { ACPI_DEBUG_PRINT((ACPI_DB_NAMES, "No Name string - %s\n", char_buf)); } } else if (index == 0) { /* */ ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Leading character is not alpha: %02Xh (not a name)\n", char_buf[0])); status = AE_CTRL_PENDING; } else { /* */ status = AE_AML_BAD_NAME; ACPI_ERROR((AE_INFO, "Bad character 0x%02x in name, at %p", *aml_address, aml_address)); } *in_aml_address = ACPI_CAST_PTR(u8, aml_address); return_ACPI_STATUS(status); }
ACPI_TABLE_HEADER * OsGetTable ( char *Signature) { HKEY Handle = NULL; ULONG i; LONG Status; ULONG Type; ULONG NameSize; ULONG DataSize; HKEY SubKey; ACPI_TABLE_HEADER *ReturnTable; /* Get a handle to the table key */ while (1) { ACPI_STRCPY (KeyBuffer, "HARDWARE\\ACPI\\"); ACPI_STRCAT (KeyBuffer, Signature); Status = RegOpenKeyEx (HKEY_LOCAL_MACHINE, KeyBuffer, 0L, KEY_ALL_ACCESS, &Handle); if (Status != ERROR_SUCCESS) { /* * Somewhere along the way, MS changed the registry entry for * the FADT from * HARDWARE/ACPI/FACP to * HARDWARE/ACPI/FADT. * * This code allows for both. */ if (ACPI_COMPARE_NAME (Signature, "FACP")) { Signature = "FADT"; } else { AcpiOsPrintf ("Could not find %s in registry at %s\n", Signature, KeyBuffer); return (NULL); } } else { break; } } /* Actual data for table is down a couple levels */ for (i = 0; ;) { Status = RegEnumKey (Handle, i, KeyBuffer, sizeof (KeyBuffer)); i += 1; if (Status == ERROR_NO_MORE_ITEMS) { break; } Status = RegOpenKey (Handle, KeyBuffer, &SubKey); if (Status != ERROR_SUCCESS) { AcpiOsPrintf ("Could not open %s entry\n", Signature); return (NULL); } RegCloseKey (Handle); Handle = SubKey; i = 0; } /* Find the (binary) table entry */ for (i = 0; ;) { NameSize = sizeof (KeyBuffer); Status = RegEnumValue (Handle, i, KeyBuffer, &NameSize, NULL, &Type, NULL, 0); if (Status != ERROR_SUCCESS) { AcpiOsPrintf ("Could not get %s registry entry\n", Signature); return (NULL); } if (Type == REG_BINARY) { break; } i += 1; } /* Get the size of the table */ Status = RegQueryValueEx (Handle, KeyBuffer, NULL, NULL, NULL, &DataSize); if (Status != ERROR_SUCCESS) { AcpiOsPrintf ("Could not read the %s table size\n", Signature); return (NULL); } /* Allocate a new buffer for the table */ ReturnTable = AcpiOsAllocate (DataSize); if (!ReturnTable) { goto Cleanup; } /* Get the actual table from the registry */ Status = RegQueryValueEx (Handle, KeyBuffer, NULL, NULL, (UCHAR *) ReturnTable, &DataSize); if (Status != ERROR_SUCCESS) { AcpiOsPrintf ("Could not read %s data\n", Signature); AcpiOsFree (ReturnTable); return (NULL); } Cleanup: RegCloseKey (Handle); return (ReturnTable); }
static char * AcpiGetTagPathname ( ACPI_NAMESPACE_NODE *BufferNode, ACPI_NAMESPACE_NODE *ResourceNode, UINT32 BitIndex) { ACPI_STATUS Status; UINT32 ResourceBitIndex; UINT8 ResourceTableIndex; ACPI_SIZE RequiredSize; char *Pathname; AML_RESOURCE *Aml; ACPI_PARSE_OBJECT *Op; char *InternalPath; char *Tag; /* Get the Op that contains the actual buffer data */ Op = BufferNode->Op->Common.Value.Arg; Op = Op->Common.Next; if (!Op) { return (NULL); } /* Get the individual resource descriptor and validate it */ Aml = ACPI_CAST_PTR (AML_RESOURCE, &Op->Named.Data[ResourceNode->Value]); Status = AcpiUtValidateResource (Aml, &ResourceTableIndex); if (ACPI_FAILURE (Status)) { return (NULL); } /* Get offset into this descriptor (from offset into entire buffer) */ ResourceBitIndex = BitIndex - ACPI_MUL_8 (ResourceNode->Value); /* Get the tag associated with this resource descriptor and offset */ Tag = AcpiDmGetResourceTag (ResourceBitIndex, Aml, ResourceTableIndex); if (!Tag) { return (NULL); } /* * Now that we know that we have a reference that can be converted to a * symbol, change the name of the resource to a unique name. */ AcpiDmUpdateResourceName (ResourceNode); /* Get the full pathname to the parent buffer */ RequiredSize = AcpiNsGetPathnameLength (BufferNode); if (!RequiredSize) { return (NULL); } Pathname = ACPI_ALLOCATE_ZEROED (RequiredSize + ACPI_PATH_SEGMENT_LENGTH); if (!Pathname) { return (NULL); } Status = AcpiNsBuildExternalPath (BufferNode, RequiredSize, Pathname); if (ACPI_FAILURE (Status)) { return (NULL); } /* * Create the full path to the resource and tag by: remove the buffer name, * append the resource descriptor name, append a dot, append the tag name. * * TBD: Always using the full path is a bit brute force, the path can be * often be optimized with carats (if the original buffer namepath is a * single nameseg). This doesn't really matter, because these paths do not * end up in the final compiled AML, it's just an appearance issue for the * disassembled code. */ Pathname[ACPI_STRLEN (Pathname) - ACPI_NAME_SIZE] = 0; ACPI_STRNCAT (Pathname, ResourceNode->Name.Ascii, ACPI_NAME_SIZE); ACPI_STRCAT (Pathname, "."); ACPI_STRNCAT (Pathname, Tag, ACPI_NAME_SIZE); /* Internalize the namepath to AML format */ AcpiNsInternalizeName (Pathname, &InternalPath); ACPI_FREE (Pathname); return (InternalPath); }
static acpi_status acpi_ex_name_segment(u8 ** in_aml_address, char *name_string) { char *aml_address = (void *)*in_aml_address; acpi_status status = AE_OK; u32 index; char char_buf[5]; ACPI_FUNCTION_TRACE(ex_name_segment); /* * If first character is a digit, then we know that we aren't looking at a * valid name segment */ char_buf[0] = *aml_address; if ('0' <= char_buf[0] && char_buf[0] <= '9') { ACPI_ERROR((AE_INFO, "Invalid leading digit: %c", char_buf[0])); return_ACPI_STATUS(AE_CTRL_PENDING); } ACPI_DEBUG_PRINT((ACPI_DB_LOAD, "Bytes from stream:\n")); for (index = 0; (index < ACPI_NAME_SIZE) && (acpi_ut_valid_acpi_char(*aml_address, 0)); index++) { char_buf[index] = *aml_address++; ACPI_DEBUG_PRINT((ACPI_DB_LOAD, "%c\n", char_buf[index])); } /* Valid name segment */ if (index == 4) { /* Found 4 valid characters */ char_buf[4] = '\0'; if (name_string) { ACPI_STRCAT(name_string, char_buf); ACPI_DEBUG_PRINT((ACPI_DB_NAMES, "Appended to - %s\n", name_string)); } else { ACPI_DEBUG_PRINT((ACPI_DB_NAMES, "No Name string - %s\n", char_buf)); } } else if (index == 0) { /* * First character was not a valid name character, * so we are looking at something other than a name. */ ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Leading character is not alpha: %02Xh (not a name)\n", char_buf[0])); status = AE_CTRL_PENDING; } else { /* * Segment started with one or more valid characters, but fewer than * the required 4 */ status = AE_AML_BAD_NAME; ACPI_ERROR((AE_INFO, "Bad character 0x%02x in name, at %p", *aml_address, aml_address)); } *in_aml_address = ACPI_CAST_PTR(u8, aml_address); return_ACPI_STATUS(status); }
int ap_write_to_binary_file(struct acpi_table_header *table, u32 instance) { char filename[ACPI_NAME_SIZE + 16]; char instance_str[16]; ACPI_FILE file; size_t actual; u32 table_length; /* Obtain table length */ table_length = ap_get_table_length(table); /* Construct lower-case filename from the table local signature */ if (ACPI_VALIDATE_RSDP_SIG(table->signature)) { ACPI_MOVE_NAME(filename, ACPI_RSDP_NAME); } else { ACPI_MOVE_NAME(filename, table->signature); } filename[0] = (char)ACPI_TOLOWER(filename[0]); filename[1] = (char)ACPI_TOLOWER(filename[1]); filename[2] = (char)ACPI_TOLOWER(filename[2]); filename[3] = (char)ACPI_TOLOWER(filename[3]); filename[ACPI_NAME_SIZE] = 0; /* Handle multiple SSDts - create different filenames for each */ if (instance > 0) { acpi_ut_snprintf(instance_str, sizeof(instance_str), "%u", instance); ACPI_STRCAT(filename, instance_str); } ACPI_STRCAT(filename, ACPI_TABLE_FILE_SUFFIX); if (gbl_verbose_mode) { acpi_log_error ("Writing [%4.4s] to binary file: %s 0x%X (%u) bytes\n", table->signature, filename, table->length, table->length); } /* Open the file and dump the entire table in binary mode */ file = acpi_os_open_file(filename, ACPI_FILE_WRITING | ACPI_FILE_BINARY); if (!file) { acpi_log_error("Could not open output file: %s\n", filename); return (-1); } actual = acpi_os_write_file(file, table, 1, table_length); if (actual != table_length) { acpi_log_error("Error writing binary output file: %s\n", filename); acpi_os_close_file(file); return (-1); } acpi_os_close_file(file); return (0); }
int ApWriteToBinaryFile ( ACPI_TABLE_HEADER *Table, UINT32 Instance) { char Filename[ACPI_NAME_SIZE + 16]; char InstanceStr [16]; ACPI_FILE File; size_t Actual; UINT32 TableLength; /* Obtain table length */ TableLength = ApGetTableLength (Table); /* Construct lower-case filename from the table local signature */ if (ACPI_VALIDATE_RSDP_SIG (Table->Signature)) { ACPI_MOVE_NAME (Filename, ACPI_RSDP_NAME); } else { ACPI_MOVE_NAME (Filename, Table->Signature); } Filename[0] = (char) ACPI_TOLOWER (Filename[0]); Filename[1] = (char) ACPI_TOLOWER (Filename[1]); Filename[2] = (char) ACPI_TOLOWER (Filename[2]); Filename[3] = (char) ACPI_TOLOWER (Filename[3]); Filename[ACPI_NAME_SIZE] = 0; /* Handle multiple SSDTs - create different filenames for each */ if (Instance > 0) { AcpiUtSnprintf (InstanceStr, sizeof (InstanceStr), "%u", Instance); ACPI_STRCAT (Filename, InstanceStr); } ACPI_STRCAT (Filename, ACPI_TABLE_FILE_SUFFIX); if (Gbl_VerboseMode) { AcpiLogError ( "Writing [%4.4s] to binary file: %s 0x%X (%u) bytes\n", Table->Signature, Filename, Table->Length, Table->Length); } /* Open the file and dump the entire table in binary mode */ File = AcpiOsOpenFile (Filename, ACPI_FILE_WRITING | ACPI_FILE_BINARY); if (!File) { AcpiLogError ("Could not open output file: %s\n", Filename); return (-1); } Actual = AcpiOsWriteFile (File, Table, 1, TableLength); if (Actual != TableLength) { AcpiLogError ("Error writing binary output file: %s\n", Filename); AcpiOsCloseFile (File); return (-1); } AcpiOsCloseFile (File); return (0); }
static ACPI_STATUS AcpiExNameSegment ( UINT8 **InAmlAddress, char *NameString) { char *AmlAddress = (void *) *InAmlAddress; ACPI_STATUS Status = AE_OK; UINT32 Index; char CharBuf[5]; ACPI_FUNCTION_TRACE (ExNameSegment); /* * If first character is a digit, then we know that we aren't looking at a * valid name segment */ CharBuf[0] = *AmlAddress; if ('0' <= CharBuf[0] && CharBuf[0] <= '9') { ACPI_ERROR ((AE_INFO, "Invalid leading digit: %c", CharBuf[0])); return_ACPI_STATUS (AE_CTRL_PENDING); } ACPI_DEBUG_PRINT ((ACPI_DB_LOAD, "Bytes from stream:\n")); for (Index = 0; (Index < ACPI_NAME_SIZE) && (AcpiUtValidAcpiChar (*AmlAddress, 0)); Index++) { CharBuf[Index] = *AmlAddress++; ACPI_DEBUG_PRINT ((ACPI_DB_LOAD, "%c\n", CharBuf[Index])); } /* Valid name segment */ if (Index == 4) { /* Found 4 valid characters */ CharBuf[4] = '\0'; if (NameString) { ACPI_STRCAT (NameString, CharBuf); ACPI_DEBUG_PRINT ((ACPI_DB_NAMES, "Appended to - %s\n", NameString)); } else { ACPI_DEBUG_PRINT ((ACPI_DB_NAMES, "No Name string - %s\n", CharBuf)); } } else if (Index == 0) { /* * First character was not a valid name character, * so we are looking at something other than a name. */ ACPI_DEBUG_PRINT ((ACPI_DB_INFO, "Leading character is not alpha: %02Xh (not a name)\n", CharBuf[0])); Status = AE_CTRL_PENDING; } else { /* * Segment started with one or more valid characters, but fewer than * the required 4 */ Status = AE_AML_BAD_NAME; ACPI_ERROR ((AE_INFO, "Bad character 0x%02x in name, at %p", *AmlAddress, AmlAddress)); } *InAmlAddress = ACPI_CAST_PTR (UINT8, AmlAddress); return_ACPI_STATUS (Status); }
static char * AcpiDmNormalizeParentPrefix ( ACPI_PARSE_OBJECT *Op, char *Path) { ACPI_NAMESPACE_NODE *Node; char *Fullpath; char *ParentPath; ACPI_SIZE Length; /* Search upwards in the parse tree until we reach a namespace node */ while (Op) { if (Op->Common.Node) { break; } Op = Op->Common.Parent; } if (!Op) { return (NULL); } /* * Find the actual parent node for the reference: * Remove all carat prefixes from the input path. * There may be multiple parent prefixes (For example, ^^^M000) */ Node = Op->Common.Node; while (Node && (*Path == (UINT8) AML_PARENT_PREFIX)) { Node = AcpiNsGetParentNode (Node); Path++; } if (!Node) { return (NULL); } /* Get the full pathname for the parent node */ ParentPath = AcpiNsGetExternalPathname (Node); if (!ParentPath) { return (NULL); } Length = (ACPI_STRLEN (ParentPath) + ACPI_STRLEN (Path) + 1); Fullpath = ACPI_ALLOCATE_ZEROED (Length); if (!Fullpath) { goto Cleanup; } /* * Concatenate parent fullpath and path. For example, * parent fullpath "\_SB_", Path "^INIT", Fullpath "\_SB_.INIT" * * Copy the parent path */ ACPI_STRCAT (Fullpath, ParentPath); /* Add dot separator (don't need dot if parent fullpath is a single "\") */ if (ParentPath[1]) { ACPI_STRCAT (Fullpath, "."); } /* Copy child path (carat parent prefix(es) were skipped above) */ ACPI_STRCAT (Fullpath, Path); Cleanup: ACPI_FREE (ParentPath); return (Fullpath); }