FreeBSD/sys/contrib/dev/acpica/compiler/dttemplate.c
/*******************************************************************************
 *
 * FUNCTION:    DtCreateOneTemplate
 *
 * PARAMETERS:  Signature           - ACPI signature, NULL terminated.
 *              TableCount          - Used for SSDTs in same file as DSDT
 *              TableData           - Entry in ACPI table data structure.
 *                                    NULL if a special ACPI table.
 *
 * RETURN:      Status
 *
 * DESCRIPTION: Create one template source file for the requested ACPI table.
 *
 ******************************************************************************/
DtCreateOneTemplate
PARAMETERS:  Signature           - ACPI signature, NULL terminated.
TableCount          - Used for SSDTs in same file as DSDT
TableData           - Entry in ACPI table data structure.
NULL if a special ACPI table.

Status

Create one template source file for the requested ACPI table.
DtCreateOneTemplate PARAMETERS : Signature - ACPI signature NULL terminated . TableCount - Used for SSDTs in same file as DSDT TableData - Entry in ACPI table data structure . NULL if a special ACPI table . Status Create one template source file for the requested ACPI table .
static ACPI_STATUS
DtCreateOneTemplate (
    char                    *Signature,
    UINT32                  TableCount,
    const ACPI_DMTABLE_DATA  *TableData)
{
    char                    *DisasmFilename;
    FILE                    *File;
    ACPI_STATUS             Status = AE_OK;
    int                     Actual;
    UINT32                  i;
    DisasmFilename = FlGenerateFilename (
        Signature, FILE_SUFFIX_ASL_CODE);
    if (!DisasmFilename)
    {
        fprintf (stderr, "Could not generate output filename\n");
        return (AE_ERROR);
    }
    AcpiUtStrlwr (DisasmFilename);
    if (!UtQueryForOverwrite (DisasmFilename))
    {
        return (AE_ERROR);
    }
    File = fopen (DisasmFilename, "w+");
    if (!File)
    {
        fprintf (stderr, "Could not open output file %s\n",
            DisasmFilename);
        return (AE_ERROR);
    }
    AcpiOsRedirectOutput (File);
    AcpiOsPrintf ("/*\n");
    AcpiOsPrintf (ACPI_COMMON_HEADER ("iASL Compiler/Disassembler", " * "));
    if (TableCount == 0)
    {
        AcpiOsPrintf (" * Template for [%4.4s] ACPI Table",
            Signature);
    }
    else
    {
        AcpiOsPrintf (" * Template for [%4.4s] and %u [SSDT] ACPI Tables",
            Signature, TableCount);
    }
    if (TableData)
    {
        AcpiOsPrintf (" (static data table)\n");
        if (Gbl_VerboseTemplates)
        {
            AcpiOsPrintf (" * Format: [HexOffset DecimalOffset ByteLength]"
                "  FieldName : HexFieldValue\n */\n\n");
        }
        else
        {
            AcpiOsPrintf (" * Format: [ByteLength]"
                "  FieldName : HexFieldValue\n */\n");
        }
        AcpiDmDumpDataTable (ACPI_CAST_PTR (ACPI_TABLE_HEADER,
            TableData->Template));
    }
    else
    {
        AcpiOsPrintf (" (AML byte code table)\n");
        AcpiOsPrintf (" */\n");
        if (ACPI_COMPARE_NAME (Signature, ACPI_SIG_DSDT))
        {
            Actual = DtEmitDefinitionBlock (
                File, DisasmFilename, ACPI_SIG_DSDT, 1);
            if (Actual < 0)
            {
                Status = AE_ERROR;
                goto Cleanup;
            }
            for (i = 1; i <= TableCount; i++)
            {
                Actual = DtEmitDefinitionBlock (
                    File, DisasmFilename, ACPI_SIG_SSDT, i + 1);
                if (Actual < 0)
                {
                    Status = AE_ERROR;
                    goto Cleanup;
                }
            }
        }
        else if (ACPI_COMPARE_NAME (Signature, ACPI_SIG_SSDT))
        {
            Actual = DtEmitDefinitionBlock (
                File, DisasmFilename, ACPI_SIG_SSDT, 1);
            if (Actual < 0)
            {
                Status = AE_ERROR;
                goto Cleanup;
            }
        }
        else if (ACPI_COMPARE_NAME (Signature, ACPI_SIG_OSDT))
        {
            Actual = DtEmitDefinitionBlock (
                File, DisasmFilename, ACPI_SIG_OSDT, 1);
            if (Actual < 0)
            {
                Status = AE_ERROR;
                goto Cleanup;
            }
        }
        else if (ACPI_COMPARE_NAME (Signature, ACPI_SIG_FACS))
        {
            AcpiDmDumpDataTable (ACPI_CAST_PTR (ACPI_TABLE_HEADER,
                TemplateFacs));
        }
        else if (ACPI_COMPARE_NAME (Signature, ACPI_RSDP_NAME))
        {
            AcpiDmDumpDataTable (ACPI_CAST_PTR (ACPI_TABLE_HEADER,
                TemplateRsdp));
        }
        else
        {
            fprintf (stderr,
                "%4.4s, Unrecognized ACPI table signature\n", Signature);
            Status = AE_ERROR;
            goto Cleanup;
        }
    }
    if (TableCount == 0)
    {
        fprintf (stderr,
            "Created ACPI table template for [%4.4s], "
            "written to \"%s\"\n",
            Signature, DisasmFilename);
    }
    else
    {
        fprintf (stderr,
            "Created ACPI table templates for [%4.4s] "
            "and %u [SSDT], written to \"%s\"\n",
            Signature, TableCount, DisasmFilename);
    }
Cleanup:
    fclose (File);
    AcpiOsRedirectOutput (stdout);
    return (Status);
}
static ACPI_STATUS DtCreateOneTemplate ( char * Signature , UINT32 TableCount , const ACPI_DMTABLE_DATA * TableData ) { char * DisasmFilename ; FILE * File ; ACPI_STATUS Status = AE_OK ; int Actual ; UINT32 i ; DisasmFilename = FlGenerateFilename ( Signature , FILE_SUFFIX_ASL_CODE ) ; if ( ! DisasmFilename ) { fprintf ( stderr , " \n " ) ; return ( AE_ERROR ) ; } AcpiUtStrlwr ( DisasmFilename ) ; if ( ! UtQueryForOverwrite ( DisasmFilename ) ) { return ( AE_ERROR ) ; } File = fopen ( DisasmFilename , " " ) ; if ( ! File ) { fprintf ( stderr , " \n " , DisasmFilename ) ; return ( AE_ERROR ) ; } AcpiOsRedirectOutput ( File ) ; AcpiOsPrintf ( " \n " ) ; AcpiOsPrintf ( ACPI_COMMON_HEADER ( " " , " " ) ) ; if ( TableCount == 0 ) { AcpiOsPrintf ( " " , Signature ) ; } else { AcpiOsPrintf ( " " , Signature , TableCount ) ; } if ( TableData ) { AcpiOsPrintf ( " \n " ) ; if ( Gbl_VerboseTemplates ) { AcpiOsPrintf ( " " " \n \n \n " ) ; } else { AcpiOsPrintf ( " " " \n \n " ) ; } AcpiDmDumpDataTable ( ACPI_CAST_PTR ( ACPI_TABLE_HEADER , TableData -> Template ) ) ; } else { AcpiOsPrintf ( " \n " ) ; AcpiOsPrintf ( " \n " ) ; if ( ACPI_COMPARE_NAME ( Signature , ACPI_SIG_DSDT ) ) { Actual = DtEmitDefinitionBlock ( File , DisasmFilename , ACPI_SIG_DSDT , 1 ) ; if ( Actual < 0 ) { Status = AE_ERROR ; goto Cleanup ; } for ( i = 1 ; i <= TableCount ; i ++ ) { Actual = DtEmitDefinitionBlock ( File , DisasmFilename , ACPI_SIG_SSDT , i + 1 ) ; if ( Actual < 0 ) { Status = AE_ERROR ; goto Cleanup ; } } } else if ( ACPI_COMPARE_NAME ( Signature , ACPI_SIG_SSDT ) ) { Actual = DtEmitDefinitionBlock ( File , DisasmFilename , ACPI_SIG_SSDT , 1 ) ; if ( Actual < 0 ) { Status = AE_ERROR ; goto Cleanup ; } } else if ( ACPI_COMPARE_NAME ( Signature , ACPI_SIG_OSDT ) ) { Actual = DtEmitDefinitionBlock ( File , DisasmFilename , ACPI_SIG_OSDT , 1 ) ; if ( Actual < 0 ) { Status = AE_ERROR ; goto Cleanup ; } } else if ( ACPI_COMPARE_NAME ( Signature , ACPI_SIG_FACS ) ) { AcpiDmDumpDataTable ( ACPI_CAST_PTR ( ACPI_TABLE_HEADER , TemplateFacs ) ) ; } else if ( ACPI_COMPARE_NAME ( Signature , ACPI_RSDP_NAME ) ) { AcpiDmDumpDataTable ( ACPI_CAST_PTR ( ACPI_TABLE_HEADER , TemplateRsdp ) ) ; } else { fprintf ( stderr , " \n " , Signature ) ; Status = AE_ERROR ; goto Cleanup ; } } if ( TableCount == 0 ) { fprintf ( stderr , " " " \" \" \n " , Signature , DisasmFilename ) ; } else { fprintf ( stderr , " " " \" \" \n " , Signature , TableCount , DisasmFilename ) ; } Cleanup : fclose ( File ) ; AcpiOsRedirectOutput ( stdout ) ; return ( Status ) ; }
FUNCTION:    DtCreateOneTemplate
 PARAMETERS:  Signature           - ACPI signature, NULL terminated.
FUNCTION : DtCreateOneTemplate PARAMETERS : Signature - ACPI signature NULL terminated .
/* New file will have a .asl suffix */ /* Emit the common file header */ /* Dump the actual ACPI table */ /* Normal case, tables that appear in AcpiDmTableData */ /* Special ACPI tables - DSDT, SSDT, OSDT, FACS, RSDP */ /* Emit any requested SSDTs into the same file */