FreeBSD/sys/contrib/dev/acpica/common/adisasm.c
/******************************************************************************
 *
 * FUNCTION:    AdAmlDisassemble
 *
 * PARAMETERS:  Filename            - AML input filename
 *              OutToFile           - TRUE if output should go to a file
 *              Prefix              - Path prefix for output
 *              OutFilename         - where the filename is returned
 *
 * RETURN:      Status
 *
 * DESCRIPTION: Disassembler entry point. Disassemble an entire ACPI table.
 *
 *****************************************************************************/
AdAmlDisassemble
PARAMETERS:  Filename            - AML input filename
OutToFile           - TRUE if output should go to a file
Prefix              - Path prefix for output
OutFilename         - where the filename is returned

Status

Disassembler entry point. Disassemble an entire ACPI table.
AdAmlDisassemble PARAMETERS : Filename - AML input filename OutToFile - TRUE if output should go to a file Prefix - Path prefix for output OutFilename - where the filename is returned Status Disassembler entry point . Disassemble an entire ACPI table .
ACPI_STATUS
AdAmlDisassemble (
    BOOLEAN                 OutToFile,
    char                    *Filename,
    char                    *Prefix,
    char                    **OutFilename)
{
    ACPI_STATUS             Status;
    char                    *DisasmFilename = NULL;
    FILE                    *File = NULL;
    ACPI_TABLE_HEADER       *Table = NULL;
    ACPI_NEW_TABLE_DESC     *ListHead = NULL;
    if (Filename)
    {
        Status = AcGetAllTablesFromFile (Filename,
            ACPI_GET_ALL_TABLES, &ListHead);
        if (ACPI_FAILURE (Status))
        {
            AcpiOsPrintf ("Could not get ACPI tables from %s, %s\n",
                Filename, AcpiFormatException (Status));
            return (Status);
        }
        Status = AdDoExternalFileList (Filename);
        if (ACPI_FAILURE (Status))
        {
            return (Status);
        }
    }
    else
    {
        Status = AdGetLocalTables ();
        if (ACPI_FAILURE (Status))
        {
            AcpiOsPrintf ("Could not get ACPI tables, %s\n",
                AcpiFormatException (Status));
            return (Status);
        }
        if (!AcpiGbl_DmOpt_Disasm)
        {
            return (AE_OK);
        }
        Status = AcpiGetTable (ACPI_SIG_DSDT, 0, &Table);
        if (ACPI_FAILURE (Status))
        {
            AcpiOsPrintf ("Could not get DSDT, %s\n",
                AcpiFormatException (Status));
            return (Status);
        }
        AcpiOsPrintf ("\nDisassembly of DSDT\n");
        Prefix = AdGenerateFilename ("dsdt", Table->OemTableId);
    }
    if (OutToFile)
    {
        DisasmFilename = FlGenerateFilename (Prefix, FILE_SUFFIX_DISASSEMBLY);
        if (!DisasmFilename)
        {
            fprintf (stderr, "Could not generate output filename\n");
            Status = AE_ERROR;
            goto Cleanup;
        }
        File = fopen (DisasmFilename, "w+");
        if (!File)
        {
            fprintf (stderr, "Could not open output file %s\n",
                DisasmFilename);
            Status = AE_ERROR;
            goto Cleanup;
        }
        AcpiOsRedirectOutput (File);
    }
    *OutFilename = DisasmFilename;
    while (ListHead)
    {
        Status = AdDisassembleOneTable (ListHead->Table,
            File, Filename, DisasmFilename);
        if (ACPI_FAILURE (Status))
        {
            break;
        }
        ListHead = ListHead->Next;
    }
Cleanup:
    if (Table &&
        !AcpiGbl_ForceAmlDisassembly &&
        !AcpiUtIsAmlTable (Table))
    {
        ACPI_FREE (Table);
    }
    if (File)
    {
        fclose (File);
        AcpiOsRedirectOutput (stdout);
    }
    AcpiPsDeleteParseTree (AcpiGbl_ParseOpRoot);
    AcpiGbl_ParseOpRoot = NULL;
    return (Status);
}
ACPI_STATUS AdAmlDisassemble ( BOOLEAN OutToFile , char * Filename , char * Prefix , char * * OutFilename ) { ACPI_STATUS Status ; char * DisasmFilename = NULL ; FILE * File = NULL ; ACPI_TABLE_HEADER * Table = NULL ; ACPI_NEW_TABLE_DESC * ListHead = NULL ; if ( Filename ) { Status = AcGetAllTablesFromFile ( Filename , ACPI_GET_ALL_TABLES , & ListHead ) ; if ( ACPI_FAILURE ( Status ) ) { AcpiOsPrintf ( " \n " , Filename , AcpiFormatException ( Status ) ) ; return ( Status ) ; } Status = AdDoExternalFileList ( Filename ) ; if ( ACPI_FAILURE ( Status ) ) { return ( Status ) ; } } else { Status = AdGetLocalTables ( ) ; if ( ACPI_FAILURE ( Status ) ) { AcpiOsPrintf ( " \n " , AcpiFormatException ( Status ) ) ; return ( Status ) ; } if ( ! AcpiGbl_DmOpt_Disasm ) { return ( AE_OK ) ; } Status = AcpiGetTable ( ACPI_SIG_DSDT , 0 , & Table ) ; if ( ACPI_FAILURE ( Status ) ) { AcpiOsPrintf ( " \n " , AcpiFormatException ( Status ) ) ; return ( Status ) ; } AcpiOsPrintf ( " \n \n " ) ; Prefix = AdGenerateFilename ( " " , Table -> OemTableId ) ; } if ( OutToFile ) { DisasmFilename = FlGenerateFilename ( Prefix , FILE_SUFFIX_DISASSEMBLY ) ; if ( ! DisasmFilename ) { fprintf ( stderr , " \n " ) ; Status = AE_ERROR ; goto Cleanup ; } File = fopen ( DisasmFilename , " " ) ; if ( ! File ) { fprintf ( stderr , " \n " , DisasmFilename ) ; Status = AE_ERROR ; goto Cleanup ; } AcpiOsRedirectOutput ( File ) ; } * OutFilename = DisasmFilename ; while ( ListHead ) { Status = AdDisassembleOneTable ( ListHead -> Table , File , Filename , DisasmFilename ) ; if ( ACPI_FAILURE ( Status ) ) { break ; } ListHead = ListHead -> Next ; } Cleanup : if ( Table && ! AcpiGbl_ForceAmlDisassembly && ! AcpiUtIsAmlTable ( Table ) ) { ACPI_FREE ( Table ) ; } if ( File ) { fclose ( File ) ; AcpiOsRedirectOutput ( stdout ) ; } AcpiPsDeleteParseTree ( AcpiGbl_ParseOpRoot ) ; AcpiGbl_ParseOpRoot = NULL ; return ( Status ) ; }
FUNCTION:    AdAmlDisassemble
 PARAMETERS:  Filename            - AML input filename
              OutToFile           - TRUE if output should go to a file
              Prefix              - Path prefix for output
              OutFilename         - where the filename is returned
FUNCTION : AdAmlDisassemble PARAMETERS : Filename - AML input filename OutToFile - TRUE if output should go to a file Prefix - Path prefix for output OutFilename - where the filename is returned
/*
     * Input: AML code from either a file or via GetTables (memory or
     * registry)
     */ /* Get the list of all AML tables in the file */ /* Process any user-specified files for external objects */ /* Obtained the local tables, just disassemble the DSDT */ /*
     * Output: ASL code. Redirect to a file if requested
     */ /* Create/Open a disassembly output file */ /* Disassemble all AML tables within the file */