Improvements to listing files

date	2000.11.10.23.34.00;	author rmoore1;	state Exp;
This commit is contained in:
aystarik 2005-06-29 15:55:44 +00:00
parent 337a773a86
commit d5fb471e96
7 changed files with 1715 additions and 4046 deletions

View File

@ -2,7 +2,7 @@
/******************************************************************************
*
* Module Name: aslfiles - file I/O suppoert
* $Revision: 1.1 $
* $Revision: 1.3 $
*
*****************************************************************************/
@ -140,7 +140,8 @@ _FlOpenIncludeFile (
if (!Node)
{
AslErrorMsg (ASL_ERROR_INCLUDE_FILE_OPEN, 0, "Null parse node");
AslCommonError (ASL_ERROR, ASL_MSG_INCLUDE_FILE_OPEN,
Gbl_CurrentLineNumber, Gbl_LogicalLineNumber, "Null parse node");
return;
}
@ -150,7 +151,7 @@ _FlOpenIncludeFile (
IncFile = fopen (Node->Value.String, "r");
if (!IncFile)
{
AslErrorMsg (ASL_ERROR_INCLUDE_FILE_OPEN, Node->LineNumber, Node->Value.String);
AslError (ASL_ERROR, ASL_MSG_INCLUDE_FILE_OPEN, Node, Node->Value.String);
return;
}
@ -223,7 +224,7 @@ FlOpenInputFile (
AslCompilerin = Gbl_AslInputFile;
if (!Gbl_AslInputFile)
{
AslErrorMsg (ASL_ERROR_INPUT_FILE_OPEN, 0, InputFilename);
AslCommonError (ASL_ERROR, ASL_MSG_INPUT_FILE_OPEN, 0, 0, InputFilename);
return (AE_ERROR);
}
@ -258,7 +259,7 @@ FlOpenAmlOutputFile (
Gbl_OutputFilename = FlGenerateFilename (InputFilename, ".aml");
if (!Gbl_OutputFilename)
{
AslError (ASL_ERROR_OUTPUT_FILENAME, 0);
AslCommonError (ASL_ERROR, ASL_MSG_OUTPUT_FILENAME, 0, 0, NULL);
return (AE_ERROR);
}
}
@ -268,7 +269,7 @@ FlOpenAmlOutputFile (
Gbl_OutputAmlFile = fopen (Gbl_OutputFilename, "w+b");
if (!Gbl_OutputAmlFile)
{
AslError (ASL_ERROR_OUTPUT_FILE_OPEN, 0);
AslCommonError (ASL_ERROR, ASL_MSG_OUTPUT_FILENAME, 0, 0, Gbl_OutputFilename);
return (AE_ERROR);
}
@ -296,12 +297,12 @@ FlOpenMiscOutputFiles (
/* Create/Open a combined source output file if asked */
if (Gbl_SourceOutputFlag)
if (Gbl_SourceOutputFlag || Gbl_ListingFlag)
{
Gbl_SourceOutputFilename = FlGenerateFilename (InputFilename, ".src");
if (!Gbl_SourceOutputFilename)
{
AslError (ASL_ERROR_LISTING_FILENAME, 0);
AslCommonError (ASL_ERROR, ASL_MSG_LISTING_FILENAME, 0, 0, NULL);
return (AE_ERROR);
}
@ -310,9 +311,10 @@ FlOpenMiscOutputFiles (
Gbl_SourceOutputFile = fopen (Gbl_SourceOutputFilename, "w+");
if (!Gbl_SourceOutputFile)
{
AslError (ASL_ERROR_LISTING_FILE_OPEN, 0);
AslCommonError (ASL_ERROR, ASL_MSG_LISTING_FILENAME, 0, 0, Gbl_SourceOutputFilename);
return (AE_ERROR);
}
}
/* Create/Open a listing output file if asked */
@ -322,7 +324,7 @@ FlOpenMiscOutputFiles (
Gbl_ListingFilename = FlGenerateFilename (InputFilename, ".lst");
if (!Gbl_ListingFilename)
{
AslError (ASL_ERROR_LISTING_FILENAME, 0);
AslCommonError (ASL_ERROR, ASL_MSG_LISTING_FILENAME, 0, 0, NULL);
return (AE_ERROR);
}
@ -331,9 +333,12 @@ FlOpenMiscOutputFiles (
Gbl_ListingFile = fopen (Gbl_ListingFilename, "w+");
if (!Gbl_ListingFile)
{
AslError (ASL_ERROR_LISTING_FILE_OPEN, 0);
AslCommonError (ASL_ERROR, ASL_MSG_LISTING_FILENAME, 0, 0, Gbl_ListingFilename);
return (AE_ERROR);
}
AslCompilerSignon (Gbl_ListingFile);
AslCompilerFileHeader (Gbl_ListingFile);
}
@ -344,7 +349,7 @@ FlOpenMiscOutputFiles (
Gbl_HexFilename = FlGenerateFilename (InputFilename, ".hex");
if (!Gbl_HexFilename)
{
AslError (ASL_ERROR_LISTING_FILENAME, 0);
AslCommonError (ASL_ERROR, ASL_MSG_LISTING_FILENAME, 0, 0, NULL);
return (AE_ERROR);
}
@ -353,9 +358,12 @@ FlOpenMiscOutputFiles (
Gbl_HexFile = fopen (Gbl_HexFilename, "w+");
if (!Gbl_HexFile)
{
AslError (ASL_ERROR_LISTING_FILE_OPEN, 0);
AslCommonError (ASL_ERROR, ASL_MSG_LISTING_FILENAME, 0, 0, Gbl_HexFilename);
return (AE_ERROR);
}
AslCompilerSignon (Gbl_HexFile);
AslCompilerFileHeader (Gbl_HexFile);
}
@ -366,7 +374,7 @@ FlOpenMiscOutputFiles (
Gbl_NsFilename = FlGenerateFilename (InputFilename, ".nsp");
if (!Gbl_NsFilename)
{
AslError (ASL_ERROR_LISTING_FILENAME, 0);
AslCommonError (ASL_ERROR, ASL_MSG_LISTING_FILENAME, 0, 0, NULL);
return (AE_ERROR);
}
@ -375,9 +383,12 @@ FlOpenMiscOutputFiles (
Gbl_NsFile = fopen (Gbl_NsFilename, "w+");
if (!Gbl_NsFile)
{
AslError (ASL_ERROR_LISTING_FILE_OPEN, 0);
AslCommonError (ASL_ERROR, ASL_MSG_LISTING_FILENAME, 0, 0, Gbl_NsFilename);
return (AE_ERROR);
}
AslCompilerSignon (Gbl_NsFile);
AslCompilerFileHeader (Gbl_NsFile);
}
@ -388,7 +399,7 @@ FlOpenMiscOutputFiles (
Gbl_DebugFilename = FlGenerateFilename (InputFilename, ".txt");
if (!Gbl_DebugFilename)
{
AslError (ASL_ERROR_DEBUG_FILENAME, 0);
AslCommonError (ASL_ERROR, ASL_MSG_DEBUG_FILENAME, 0, 0, NULL);
return (AE_ERROR);
}
@ -397,9 +408,12 @@ FlOpenMiscOutputFiles (
Gbl_DebugFile = freopen (Gbl_DebugFilename, "w+", stderr);
if (!Gbl_DebugFile)
{
AslError (ASL_ERROR_DEBUG_FILE_OPEN, 0);
AslCommonError (ASL_ERROR, ASL_MSG_DEBUG_FILENAME, 0, 0, Gbl_DebugFilename);
return (AE_ERROR);
}
AslCompilerSignon (Gbl_DebugFile);
AslCompilerFileHeader (Gbl_DebugFile);
}
@ -407,7 +421,6 @@ FlOpenMiscOutputFiles (
}
/*******************************************************************************
*
* FUNCTION:
@ -421,45 +434,76 @@ FlOpenMiscOutputFiles (
******************************************************************************/
void
FlDoHexOutput (void)
FlCloseListingFile (void)
{
UINT32 j;
UINT8 FileByte;
UINT8 Buffer[4];
if (!Gbl_ListingFlag)
{
return;
}
LsFlushListingBuffer ();
fprintf (Gbl_ListingFile, "\n\nSummary of errors and warnings\n\n");
AePrintErrorLog (Gbl_ListingFile);
fprintf (Gbl_ListingFile, "\n\n");
fclose (Gbl_ListingFile);
if (!Gbl_SourceOutputFlag)
{
fclose (Gbl_SourceOutputFile);
unlink (Gbl_SourceOutputFilename);
}
}
/*******************************************************************************
*
* FUNCTION:
*
* PARAMETERS:
*
* RETURN:
*
* DESCRIPTION:
*
******************************************************************************/
void
FlCloseSourceOutputFile (void)
{
if (!Gbl_SourceOutputFlag)
{
return;
}
fclose (Gbl_SourceOutputFile);
}
/*******************************************************************************
*
* FUNCTION:
*
* PARAMETERS:
*
* RETURN:
*
* DESCRIPTION:
*
******************************************************************************/
void
FlCloseHexOutputFile (void)
{
if (!Gbl_HexOutputFlag)
{
return;
}
/* Start at the beginning of the AML file */
fseek (Gbl_OutputAmlFile, 0, SEEK_SET);
j = 0;
while (fread (&FileByte, 1, 1, Gbl_OutputAmlFile))
{
/*
* Convert each AML byte to hex
*/
UtConvertByteToHex (FileByte, Buffer);
fwrite (Buffer, 4, 1, Gbl_HexFile);
fwrite (", ", 2, 1, Gbl_HexFile);
/* An occasional linefeed improves readability */
j++;
if (j >= 12)
{
fwrite ("\n", 1, 1, Gbl_HexFile);
j = 0;
}
}
fclose (Gbl_HexFile);
}

View File

@ -2,7 +2,7 @@
/******************************************************************************
*
* Module Name: asllength - Tree walk to determine package and opcode lengths
* $Revision: 1.35 $
* $Revision: 1.9 $
*
*****************************************************************************/
@ -10,8 +10,8 @@
*
* 1. Copyright Notice
*
* Some or all of this work - Copyright (c) 1999 - 2005, Intel Corp.
* All rights reserved.
* Some or all of this work - Copyright (c) 1999, Intel Corp. All rights
* reserved.
*
* 2. License
*
@ -116,132 +116,138 @@
*****************************************************************************/
#include "aslcompiler.h"
#include "aslcompiler.y.h"
#include "AslCompiler.h"
#include "AslCompiler.y.h"
#include "amlcode.h"
#include "acnamesp.h"
#define _COMPONENT ACPI_COMPILER
ACPI_MODULE_NAME ("asllength")
/* Local prototypes */
static UINT8
CgGetPackageLenByteCount (
ACPI_PARSE_OBJECT *Op,
UINT32 PackageLength);
static void
CgGenerateAmlOpcodeLength (
ACPI_PARSE_OBJECT *Op);
#define _COMPONENT MISCELLANEOUS
MODULE_NAME ("asllength")
#ifdef ACPI_OBSOLETE_FUNCTIONS
/*******************************************************************************
*
* FUNCTION:
*
* PARAMETERS:
*
* RETURN:
*
* DESCRIPTION:
*
******************************************************************************/
void
LnInitLengthsWalk (
ASL_PARSE_NODE *Node,
UINT32 Level,
void *Context)
{
// Node->AmlLength = 0;
// Node->AmlOpcodeLength = 0;
Node->AmlSubtreeLength = 0;
// Node->AmlPkgLenBytes = 0;
}
/*******************************************************************************
*
* FUNCTION:
*
* PARAMETERS:
*
* RETURN:
*
* DESCRIPTION:
*
******************************************************************************/
void
LnPackageLengthWalk (
ASL_PARSE_NODE *Node,
UINT32 Level,
void *Context)
{
/*
* generate the subtree length and
* bubble it up to the parent
*/
CgGenerateAmlLengths (Node);
if ((Node->Parent) &&
(Node->ParseOpcode != DEFAULT_ARG))
{
Node->Parent->AmlSubtreeLength += (Node->AmlLength +
Node->AmlOpcodeLength +
Node->AmlPkgLenBytes +
Node->AmlSubtreeLength);
}
}
/*******************************************************************************
*
* FUNCTION:
*
* PARAMETERS:
*
* RETURN:
*
* DESCRIPTION:
*
******************************************************************************/
void
LnAdjustLengthToRoot (
ACPI_PARSE_OBJECT *Op,
UINT32 LengthDelta);
#endif
/*******************************************************************************
*
* FUNCTION: LnInitLengthsWalk
*
* PARAMETERS: ASL_WALK_CALLBACK
*
* RETURN: Status
*
* DESCRIPTION: Walk callback to initialize (and re-initialize) the node
* subtree length(s) to zero. The Subtree lengths are bubbled
* up to the root node in order to get a total AML length.
*
******************************************************************************/
ACPI_STATUS
LnInitLengthsWalk (
ACPI_PARSE_OBJECT *Op,
UINT32 Level,
void *Context)
ASL_PARSE_NODE *PsNode,
UINT32 LengthDelta)
{
ASL_PARSE_NODE *Node;
Op->Asl.AmlSubtreeLength = 0;
return (AE_OK);
}
/* Adjust all subtree lengths up to the root */
/*******************************************************************************
*
* FUNCTION: LnPackageLengthWalk
*
* PARAMETERS: ASL_WALK_CALLBACK
*
* RETURN: Status
*
* DESCRIPTION: Walk callback to calculate the total AML length.
* 1) Calculate the AML lengths (opcode, package length, etc.) for
* THIS node.
* 2) Bubbble up all of these lengths to the parent node by summing
* them all into the parent subtree length.
*
* Note: The SubtreeLength represents the total AML length of all child nodes
* in all subtrees under a given node. Therefore, once this walk is
* complete, the Root Node subtree length is the AML length of the entire
* tree (and thus, the entire ACPI table)
*
******************************************************************************/
ACPI_STATUS
LnPackageLengthWalk (
ACPI_PARSE_OBJECT *Op,
UINT32 Level,
void *Context)
{
/* Generate the AML lengths for this node */
CgGenerateAmlLengths (Op);
/* Bubble up all lengths (this node and all below it) to the parent */
if ((Op->Asl.Parent) &&
(Op->Asl.ParseOpcode != PARSEOP_DEFAULT_ARG))
Node = PsNode->Parent;
while (Node)
{
Op->Asl.Parent->Asl.AmlSubtreeLength += (Op->Asl.AmlLength +
Op->Asl.AmlOpcodeLength +
Op->Asl.AmlPkgLenBytes +
Op->Asl.AmlSubtreeLength);
Node->AmlSubtreeLength -= LengthDelta;
Node = Node->Parent;
}
return (AE_OK);
/* Adjust the global table length */
Gbl_TableLength -= LengthDelta;
}
/*******************************************************************************
*
* FUNCTION: CgGetPackageLenByteCount
* FUNCTION:
*
* PARAMETERS: Op - Parse node
* PackageLength - Length to be encoded
* PARAMETERS:
*
* RETURN: Required length of the package length encoding
* RETURN:
*
* DESCRIPTION: Calculate the number of bytes required to encode the given
* package length.
* DESCRIPTION:
*
******************************************************************************/
static UINT8
UINT8
CgGetPackageLenByteCount (
ACPI_PARSE_OBJECT *Op,
ASL_PARSE_NODE *Node,
UINT32 PackageLength)
{
/*
/*
* Determine the number of bytes required to encode the package length
* Note: the package length includes the number of bytes used to encode
* the package length, so we must account for this also.
*/
if (PackageLength <= (0x0000003F - 1))
if (PackageLength <= (0x0000003F - 1))
{
return (1);
}
@ -261,271 +267,198 @@ CgGetPackageLenByteCount (
{
/* Fatal error - the package length is too large to encode */
AslError (ASL_ERROR, ASL_MSG_ENCODING_LENGTH, Op, NULL);
AslError (ASL_ERROR, ASL_MSG_ENCODING_LENGTH, Node, NULL);
}
return (0);
}
/*******************************************************************************
*
* FUNCTION: CgGenerateAmlOpcodeLength
* FUNCTION:
*
* PARAMETERS: Op - Parse node whose AML opcode lengths will be
* calculated
* PARAMETERS:
*
* RETURN: None.
* RETURN:
*
* DESCRIPTION: Calculate the AmlOpcodeLength, AmlPkgLenBytes, and AmlLength
* fields for this node.
* DESCRIPTION:
*
******************************************************************************/
static void
void
CgGenerateAmlOpcodeLength (
ACPI_PARSE_OBJECT *Op)
ASL_PARSE_NODE *Node)
{
/* Check for two-byte opcode */
if (Op->Asl.AmlOpcode > 0x00FF)
if (Node->AmlOpcode > 0x00FF)
{
Op->Asl.AmlOpcodeLength = 2;
Node->AmlOpcodeLength = 2;
}
else
{
Op->Asl.AmlOpcodeLength = 1;
Node->AmlOpcodeLength = 1;
}
/* Does this opcode have an associated "PackageLength" field? */
Op->Asl.AmlPkgLenBytes = 0;
if (Op->Asl.CompileFlags & NODE_AML_PACKAGE)
Node->AmlPkgLenBytes = 0;
if (Node->Flags & NODE_AML_PACKAGE)
{
Op->Asl.AmlPkgLenBytes = CgGetPackageLenByteCount (
Op, Op->Asl.AmlSubtreeLength);
Node->AmlPkgLenBytes = CgGetPackageLenByteCount (Node, Node->AmlSubtreeLength);
}
/* Data opcode lengths are easy */
switch (Op->Asl.AmlOpcode)
switch (Node->AmlOpcode)
{
case AML_BYTE_OP:
Op->Asl.AmlLength = 1;
Node->AmlLength = 1;
break;
case AML_WORD_OP:
Op->Asl.AmlLength = 2;
Node->AmlLength = 2;
break;
case AML_DWORD_OP:
Op->Asl.AmlLength = 4;
Node->AmlLength = 4;
break;
case AML_QWORD_OP:
Op->Asl.AmlLength = 8;
break;
default:
/* All data opcodes must be above */
Node->AmlLength = 8;
break;
}
}
/*******************************************************************************
*
* FUNCTION: CgGenerateAmlLengths
* FUNCTION:
*
* PARAMETERS: Op - Parse node
* PARAMETERS:
*
* RETURN: None.
* RETURN:
*
* DESCRIPTION: Generate internal length fields based on the AML opcode or
* parse opcode.
* DESCRIPTION:
*
******************************************************************************/
void
CgGenerateAmlLengths (
ACPI_PARSE_OBJECT *Op)
ASL_PARSE_NODE *Node)
{
char *Buffer;
ACPI_STATUS Status;
switch (Op->Asl.AmlOpcode)
switch (Node->AmlOpcode)
{
case AML_RAW_DATA_BYTE:
Op->Asl.AmlOpcodeLength = 0;
Op->Asl.AmlLength = 1;
Node->AmlOpcodeLength = 0;
Node->AmlLength = 1;
return;
case AML_RAW_DATA_WORD:
Op->Asl.AmlOpcodeLength = 0;
Op->Asl.AmlLength = 2;
Node->AmlOpcodeLength = 0;
Node->AmlLength = 2;
return;
case AML_RAW_DATA_DWORD:
Op->Asl.AmlOpcodeLength = 0;
Op->Asl.AmlLength = 4;
Node->AmlOpcodeLength = 0;
Node->AmlLength = 4;
return;
case AML_RAW_DATA_QWORD:
Op->Asl.AmlOpcodeLength = 0;
Op->Asl.AmlLength = 8;
Node->AmlOpcodeLength = 0;
Node->AmlLength = 8;
return;
case AML_RAW_DATA_BUFFER:
/* Aml length is/was set by creator */
Op->Asl.AmlOpcodeLength = 0;
Node->AmlOpcodeLength = 0;
return;
case AML_RAW_DATA_CHAIN:
/* Aml length is/was set by creator */
Op->Asl.AmlOpcodeLength = 0;
Node->AmlOpcodeLength = 0;
return;
default:
break;
}
switch (Op->Asl.ParseOpcode)
switch (Node->ParseOpcode)
{
case PARSEOP_DEFINITIONBLOCK:
Gbl_TableLength = sizeof (ACPI_TABLE_HEADER) +
Op->Asl.AmlSubtreeLength;
case DEFINITIONBLOCK:
Gbl_TableLength = sizeof (ACPI_TABLE_HEADER) + Node->AmlSubtreeLength;
break;
case PARSEOP_NAMESEG:
Op->Asl.AmlOpcodeLength = 0;
Op->Asl.AmlLength = 4;
Op->Asl.ExternalName = Op->Asl.Value.String;
case NAMESEG:
Node->AmlOpcodeLength = 0;
Node->AmlLength = 4;
Node->ExternalName = Node->Value.String;
break;
case PARSEOP_NAMESTRING:
case PARSEOP_METHODCALL:
if (Op->Asl.CompileFlags & NODE_NAME_INTERNALIZED)
case NAMESTRING:
case METHODCALL:
if (Node->Flags & NODE_NAME_INTERNALIZED)
{
break;
}
Op->Asl.AmlOpcodeLength = 0;
Status = UtInternalizeName (Op->Asl.Value.String, &Buffer);
Node->AmlOpcodeLength = 0;
Status = AcpiNsInternalizeName (Node->Value.String, &Buffer);
if (ACPI_FAILURE (Status))
{
DbgPrint (ASL_DEBUG_OUTPUT,
"Failure from internalize name %X\n", Status);
DbgPrint ("Failure from internalize name %X\n", Status);
break;
}
Op->Asl.ExternalName = Op->Asl.Value.String;
Op->Asl.Value.String = Buffer;
Op->Asl.CompileFlags |= NODE_NAME_INTERNALIZED;
Node->ExternalName = Node->Value.String;
Node->Value.String = Buffer;
Node->Flags |= NODE_NAME_INTERNALIZED;
Op->Asl.AmlLength = strlen (Buffer);
/*
Node->AmlLength = strlen (Buffer);
/*
* Check for single backslash reference to root,
* make it a null terminated string in the AML
*/
if (Op->Asl.AmlLength == 1)
if (Node->AmlLength == 1)
{
Op->Asl.AmlLength = 2;
Node->AmlLength = 2;
}
break;
case PARSEOP_STRING_LITERAL:
Op->Asl.AmlOpcodeLength = 1;
/* Get null terminator */
Op->Asl.AmlLength = strlen (Op->Asl.Value.String) + 1;
case STRING_LITERAL:
Node->AmlOpcodeLength = 1;
Node->AmlLength = strlen (Node->Value.String) + 1; /* Get null terminator */
break;
case PARSEOP_PACKAGE_LENGTH:
Op->Asl.AmlOpcodeLength = 0;
Op->Asl.AmlPkgLenBytes = CgGetPackageLenByteCount (Op,
(UINT32) Op->Asl.Value.Integer);
case PACKAGE_LENGTH:
Node->AmlOpcodeLength = 0;
Node->AmlPkgLenBytes = CgGetPackageLenByteCount (Node, Node->Value.Integer32);
break;
case PARSEOP_RAW_DATA:
Op->Asl.AmlOpcodeLength = 0;
case RAW_DATA:
Node->AmlOpcodeLength = 0;
// Node->AmlLength = 1;
break;
case PARSEOP_DEFAULT_ARG:
case PARSEOP_EXTERNAL:
case PARSEOP_INCLUDE:
case PARSEOP_INCLUDE_END:
/* Ignore the "default arg" nodes, they are extraneous at this point */
/* Ignore the "default arg" nodes, they are extraneous at this point */
case DEFAULT_ARG:
break;
default:
CgGenerateAmlOpcodeLength (Op);
CgGenerateAmlOpcodeLength (Node);
break;
}
}
#ifdef ACPI_OBSOLETE_FUNCTIONS
/*******************************************************************************
*
* FUNCTION: LnAdjustLengthToRoot
*
* PARAMETERS: Op - Node whose Length was changed
*
* RETURN: None.
*
* DESCRIPTION: Change the Subtree length of the given node, and bubble the
* change all the way up to the root node. This allows for
* last second changes to a package length (for example, if the
* package length encoding gets shorter or longer.)
*
******************************************************************************/
void
LnAdjustLengthToRoot (
ACPI_PARSE_OBJECT *SubtreeOp,
UINT32 LengthDelta)
{
ACPI_PARSE_OBJECT *Op;
/* Adjust all subtree lengths up to the root */
Op = SubtreeOp->Asl.Parent;
while (Op)
{
Op->Asl.AmlSubtreeLength -= LengthDelta;
Op = Op->Asl.Parent;
}
/* Adjust the global table length */
Gbl_TableLength -= LengthDelta;
}
#endif

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -2,7 +2,7 @@
/******************************************************************************
*
* Module Name: aslmain - compiler main and utilities
* $Revision: 1.84 $
* $Revision: 1.16 $
*
*****************************************************************************/
@ -10,8 +10,8 @@
*
* 1. Copyright Notice
*
* Some or all of this work - Copyright (c) 1999 - 2005, Intel Corp.
* All rights reserved.
* Some or all of this work - Copyright (c) 1999, Intel Corp. All rights
* reserved.
*
* 2. License
*
@ -116,724 +116,345 @@
*****************************************************************************/
#define _DECLARE_GLOBALS
#include "aslcompiler.h"
#include "AslCompiler.h"
#include "acnamesp.h"
#include "acapps.h"
#include "acdebug.h"
#ifdef _DEBUG
#include <crtdbg.h>
#endif
FILE *DebugFile;
UINT8 AcpiGbl_DbOutputFlags = DB_CONSOLE_OUTPUT;
ASL_ANALYSIS_WALK_INFO AnalysisWalkInfo;
char hex[] = {'0','1','2','3','4','5','6','7',
'8','9','A','B','C','D','E','F'};
#define _COMPONENT ACPI_COMPILER
ACPI_MODULE_NAME ("aslmain")
BOOLEAN AslToFile = TRUE;
BOOLEAN DoCompile = TRUE;
BOOLEAN DoSignon = TRUE;
char hex[] =
/*
* Stubs
*/
void
AcpiTbDeleteAcpiTables (void)
{
'0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'
};
}
/* Local prototypes */
static void
Options (
void);
BOOLEAN
AcpiTbSystemTablePointer (
void *Where)
{
return FALSE;
static void
HelpMessage (
void);
}
static void
Usage (
void);
void
AcpiAmlDumpOperands (
ACPI_OPERAND_OBJECT **Operands,
OPERATING_MODE InterpreterMode,
NATIVE_CHAR *Ident,
UINT32 NumLevels,
NATIVE_CHAR *Note,
NATIVE_CHAR *ModuleName,
UINT32 LineNumber)
{
}
static void
AslInitialize (
void);
ACPI_STATUS
AcpiAmlDumpOperand (
ACPI_OPERAND_OBJECT *EntryDesc)
{
return AE_OK;
}
static void
AslCommandLine (
int argc,
char **argv);
/*******************************************************************************
*
* FUNCTION: Options
* FUNCTION: Signon and FileHeader
*
* PARAMETERS: None
*
* RETURN: None
*
* RETURN: None
*
* DESCRIPTION: Display option help message
* DESCRIPTION: Display compiler signon
*
******************************************************************************/
static void
Options (
void)
void
AslCompilerSignon (
FILE *Where)
{
printf ("General Output:\n");
printf (" -p <prefix> Specify filename prefix for all output files (including .aml)\n");
printf (" -vi Less verbose errors and warnings for use with IDEs\n");
printf (" -vo Enable optimization comments\n");
printf (" -vr Disable remarks\n");
printf (" -vs Disable signon\n");
fprintf (Where, "\n%s [Version %s, %s]\n\n", CompilerId, CompilerVersion, __DATE__);
printf ("\nAML Output Files:\n");
printf (" -s<a|c> Create AML in assembler or C source file (*.asm or *.c)\n");
printf (" -i<a|c> Create assembler or C include file (*.inc or *.h)\n");
printf (" -t<a|c> Create AML in assembler or C hex table (*.hex)\n");
}
printf ("\nAML Code Generation:\n");
printf (" -oa Disable all optimizations (compatibility mode)\n");
printf (" -of Disable constant folding\n");
printf (" -oi Disable integer optimization to Zero/One/Ones\n");
printf (" -on Disable named reference string optimization\n");
printf (" -r<Revision> Override table header Revision (1-255)\n");
void
AslCompilerFileHeader (
FILE *Where)
{
printf ("\nListings:\n");
printf (" -l Create mixed listing file (ASL source and AML) (*.lst)\n");
printf (" -ln Create namespace file (*.nsp)\n");
printf (" -ls Create combined source file (expanded includes) (*.src)\n");
fprintf (Where, "Compilation of %s [%s, %s]\n\n", Gbl_InputFilename, __DATE__, __TIME__);
printf ("\nAML Disassembler:\n");
printf (" -d [file] Disassemble AML to ASL source code file (*.dsl)\n");
printf (" -dc [file] Disassemble AML and immediately compile it\n");
printf (" (Obtain DSDT from current system if no input file)\n");
printf (" -e Generate External() statements for unresolved symbols\n");
printf (" -g Get ACPI tables and write to files (*.dat)\n");
printf ("\nMiscellaneous:\n");
printf (" -a Verify source file is entirely ASCII text (0x00-0x7F)\n");
printf ("\nHelp:\n");
printf (" -h Additional help and compiler debug options\n");
printf (" -hc Display operators allowed in constant expressions\n");
printf (" -hr Display ACPI reserved method names\n");
}
/*******************************************************************************
*
* FUNCTION: HelpMessage
* FUNCTION: Usage
*
* PARAMETERS: None
*
* RETURN: None
*
* RETURN: None
*
* DESCRIPTION: Display help message
*
******************************************************************************/
static void
HelpMessage (
void)
{
printf ("AML output filename generation:\n");
printf (" Output filenames are generated by appending an extension to a common\n");
printf (" filename prefix. The filename prefix is obtained via one of the\n");
printf (" following methods (in priority order):\n");
printf (" 1) The -p option specifies the prefix\n");
printf (" 2) The prefix of the AMLFileName in the ASL Definition Block\n");
printf (" 3) The prefix of the input filename\n");
printf ("\n");
Options ();
printf ("\nCompiler Debug Options:\n");
printf (" -b<p|t|b> Create compiler debug/trace file (*.txt)\n");
printf (" Types: Parse/Tree/Both\n");
printf (" -f Ignore errors, force creation of AML output file(s)\n");
printf (" -c Parse only, no output generation\n");
printf (" -ot Display compile times\n");
printf (" -x<level> Set debug level for trace output\n");
}
/*******************************************************************************
*
* FUNCTION: Usage
*
* PARAMETERS: None
*
* RETURN: None
*
* DESCRIPTION: Display usage and option message
*
******************************************************************************/
static void
void
Usage (
void)
{
printf ("Usage: %s [Options] [InputFile]\n\n", CompilerName);
Options ();
printf ("Usage: %s <Options> <InputFile>\n\n", CompilerName);
printf ("Options: -d Create debug/trace output file (*.txt)\n");
printf (" -h Create ascii hex output file (*.hex)\n");
printf (" -i Ignore errors, always create AML file\n");
printf (" -l Create listing (mixed source/AML) file (*.lst)\n");
printf (" -n Create namespace file (*.nsp)\n");
printf (" -o <filename> Specify output file (override table header)\n");
printf (" -s Create combined (w/includes) ASL file (*.src)\n");
}
/*******************************************************************************
*
* FUNCTION: AslInitialize
* FUNCTION: main
*
* PARAMETERS: None
* PARAMETERS: Standard argc/argv
*
* RETURN: None
* RETURN: Program termination code
*
* DESCRIPTION: Initialize compiler globals
* DESCRIPTION: C main routine for the Asl Compiler
*
******************************************************************************/
static void
AslInitialize (
void)
int
main (
int argc,
char **argv)
{
UINT32 i;
UINT32 j;
ACPI_STATUS Status;
UINT32 DebugLevel = AcpiDbgLevel;
BOOLEAN BadCommandLine = FALSE;
#ifdef _DEBUG
_CrtSetDbgFlag (_CRTDBG_CHECK_ALWAYS_DF | _CrtSetDbgFlag(0));
#endif
AslGbl_ExceptionCount[0] = 0;
AslGbl_ExceptionCount[1] = 0;
AcpiDbgLevel = 0;
for (i = 0; i < ASL_NUM_FILES; i++)
{
Gbl_Files[i].Handle = NULL;
Gbl_Files[i].Filename = NULL;
}
AslCompilerSignon (stdout);
Gbl_Files[ASL_FILE_STDOUT].Handle = stdout;
Gbl_Files[ASL_FILE_STDOUT].Filename = "STDOUT";
Gbl_Files[ASL_FILE_STDERR].Handle = stderr;
Gbl_Files[ASL_FILE_STDERR].Filename = "STDERR";
}
/*******************************************************************************
*
* FUNCTION: AslCommandLine
*
* PARAMETERS: argc/argv
*
* RETURN: None
*
* DESCRIPTION: Command line processing
*
******************************************************************************/
static void
AslCommandLine (
int argc,
char **argv)
{
BOOLEAN BadCommandLine = FALSE;
ACPI_NATIVE_INT j;
/* Minimum command line contains at least one option or an input file */
/* Minimum command line contains at least the input file */
if (argc < 2)
{
AslCompilerSignon (ASL_FILE_STDOUT);
Usage ();
exit (1);
return 0;
}
/* Get the command line options */
while ((j = AcpiGetopt (argc, argv, "ab:cd^efgh^i^l^o:p:r:s:t:v:x:")) != EOF) switch (j)
while ((j = getopt (argc, argv, "dhilno:s")) != EOF) switch (j)
{
case 'a':
Gbl_CheckForAscii = TRUE;
break;
case 'b':
switch (AcpiGbl_Optarg[0])
{
case 'b':
AslCompilerdebug = 1; /* same as yydebug */
break;
case 'p':
AslCompilerdebug = 1; /* same as yydebug */
break;
case 't':
break;
default:
printf ("Unknown option: -b%s\n", AcpiGbl_Optarg);
BadCommandLine = TRUE;
break;
}
case 'd':
/* Produce debug output file */
Gbl_DebugFlag = TRUE;
AslCompilerdebug = 1; /* same as yydebug */
break;
case 'h':
/* Produce hex output file */
case 'c':
/* Parse only */
Gbl_ParseOnlyFlag = TRUE;
Gbl_HexOutputFlag = TRUE;
break;
case 'd':
switch (AcpiGbl_Optarg[0])
{
case '^':
DoCompile = FALSE;
break;
case 'c':
break;
default:
printf ("Unknown option: -d%s\n", AcpiGbl_Optarg);
BadCommandLine = TRUE;
break;
}
Gbl_DisasmFlag = TRUE;
break;
case 'e':
/* Generate external statements for unresolved symbols */
Gbl_GenerateExternals = TRUE;
break;
case 'f':
/* Ignore errors and force creation of aml file */
case 'i':
/* Ignore errors and always attempt to create aml file */
Gbl_IgnoreErrors = TRUE;
break;
case 'g':
/* Get all ACPI tables */
Gbl_GetAllTables = TRUE;
DoCompile = FALSE;
break;
case 'h':
switch (AcpiGbl_Optarg[0])
{
case '^':
HelpMessage ();
exit (0);
case 'c':
UtDisplayConstantOpcodes ();
exit (0);
case 'r':
/* reserved names */
MpDisplayReservedNames ();
exit (0);
default:
printf ("Unknown option: -h%s\n", AcpiGbl_Optarg);
BadCommandLine = TRUE;
break;
}
break;
case 'i':
switch (AcpiGbl_Optarg[0])
{
case 'a':
/* Produce assembly code include file */
Gbl_AsmIncludeOutputFlag = TRUE;
break;
case 'c':
/* Produce C include file */
Gbl_C_IncludeOutputFlag = TRUE;
break;
default:
printf ("Unknown option: -s%s\n", AcpiGbl_Optarg);
BadCommandLine = TRUE;
break;
}
break;
case 'l':
/* Produce listing file (Mixed source/aml) */
switch (AcpiGbl_Optarg[0])
{
case '^':
/* Produce listing file (Mixed source/aml) */
Gbl_ListingFlag = TRUE;
break;
case 'n':
/* Produce namespace file */
Gbl_NsOutputFlag = TRUE;
break;
case 's':
/* Produce combined source file */
Gbl_SourceOutputFlag = TRUE;
break;
default:
printf ("Unknown option: -l%s\n", AcpiGbl_Optarg);
BadCommandLine = TRUE;
break;
}
Gbl_ListingFlag = TRUE;
break;
case 'n':
/* Produce namespace file */
Gbl_NsOutputFlag = TRUE;
break;
case 'o':
switch (AcpiGbl_Optarg[0])
{
case 'a':
/* Disable all optimizations */
Gbl_FoldConstants = FALSE;
Gbl_IntegerOptimizationFlag = FALSE;
Gbl_ReferenceOptimizationFlag = FALSE;
break;
case 'f':
/* Disable folding on "normal" expressions */
Gbl_FoldConstants = FALSE;
break;
case 'i':
/* Disable integer optimization to constants */
Gbl_IntegerOptimizationFlag = FALSE;
break;
case 'n':
/* Disable named reference optimization */
Gbl_ReferenceOptimizationFlag = FALSE;
break;
case 't':
/* Display compile time(s) */
Gbl_CompileTimesFlag = TRUE;
break;
default:
printf ("Unknown option: -c%s\n", AcpiGbl_Optarg);
BadCommandLine = TRUE;
break;
}
break;
case 'p':
/* Override default AML output filename */
Gbl_OutputFilenamePrefix = AcpiGbl_Optarg;
Gbl_OutputFilename = optarg;
Gbl_UseDefaultAmlFilename = FALSE;
break;
case 'r':
Gbl_RevisionOverride = (UINT8) strtoul (AcpiGbl_Optarg, NULL, 0);
break;
case 's':
/* Produce combined source file */
switch (AcpiGbl_Optarg[0])
{
case 'a':
/* Produce assembly code output file */
Gbl_AsmOutputFlag = TRUE;
break;
case 'c':
/* Produce C hex output file */
Gbl_C_OutputFlag = TRUE;
break;
default:
printf ("Unknown option: -s%s\n", AcpiGbl_Optarg);
BadCommandLine = TRUE;
break;
}
Gbl_SourceOutputFlag = TRUE;
break;
case 't':
/* Produce hex table output file */
switch (AcpiGbl_Optarg[0])
{
case 'a':
Gbl_HexOutputFlag = HEX_OUTPUT_ASM;
break;
case 'c':
Gbl_HexOutputFlag = HEX_OUTPUT_C;
break;
default:
printf ("Unknown option: -t%s\n", AcpiGbl_Optarg);
BadCommandLine = TRUE;
break;
}
break;
case 'v':
switch (AcpiGbl_Optarg[0])
{
case 'i':
/* Less verbose error messages */
Gbl_VerboseErrors = FALSE;
break;
case 'o':
Gbl_DisplayOptimizations = TRUE;
break;
case 'r':
Gbl_DisplayRemarks = FALSE;
break;
case 's':
DoSignon = FALSE;
break;
default:
printf ("Unknown option: -v%s\n", AcpiGbl_Optarg);
BadCommandLine = TRUE;
break;
}
break;
case 'x':
AcpiDbgLevel = strtoul (AcpiGbl_Optarg, NULL, 16);
break;
default:
BadCommandLine = TRUE;
break;
}
/* Next parameter must be the input filename */
Gbl_Files[ASL_FILE_INPUT].Filename = argv[AcpiGbl_Optind];
if (!Gbl_Files[ASL_FILE_INPUT].Filename &&
!Gbl_DisasmFlag &&
!Gbl_GetAllTables)
Gbl_InputFilename = argv[optind];
if (!Gbl_InputFilename)
{
printf ("Missing input filename\n");
BadCommandLine = TRUE;
}
if (DoSignon)
{
AslCompilerSignon (ASL_FILE_STDOUT);
}
/* Abort if anything went wrong on the command line */
if (BadCommandLine)
{
printf ("\n");
Usage ();
exit (1);
}
if ((AcpiGbl_Optind + 1) < argc)
{
printf ("Warning: extra arguments (%d) after input filename are ignored\n\n",
argc - AcpiGbl_Optind - 1);
}
}
/*******************************************************************************
*
* FUNCTION: main
*
* PARAMETERS: Standard argc/argv
*
* RETURN: Program termination code
*
* DESCRIPTION: C main routine for the Asl Compiler. Handle command line
* options and begin the compile.
*
******************************************************************************/
int ACPI_SYSTEM_XFACE
main (
int argc,
char **argv)
{
ACPI_STATUS Status;
char *Prefix;
/* Init and command line */
AslInitialize ();
AslCommandLine (argc, argv);
/*
* If -p not specified, we will use the input filename as the
* output filename prefix
*/
Status = FlSplitInputPathname (Gbl_Files[ASL_FILE_INPUT].Filename,
&Gbl_DirectoryPath, &Prefix);
if (ACPI_FAILURE (Status))
{
return -1;
}
if (Gbl_UseDefaultAmlFilename)
Status = FlOpenInputFile (Gbl_InputFilename);
if (ACPI_FAILURE (Status))
{
Gbl_OutputFilenamePrefix = Prefix;
AePrintErrorLog (stderr);
return -1;
}
Status = FlOpenMiscOutputFiles (Gbl_InputFilename);
if (ACPI_FAILURE (Status))
{
AePrintErrorLog (stderr);
return -1;
}
/* AML Disassembly (Optional) */
if (Gbl_DisasmFlag || Gbl_GetAllTables)
{
/* ACPI CA subsystem initialization */
/* ACPI CA subsystem initialization */
Status = AcpiOsInitialize ();
AcpiUtInitGlobals ();
Status = AcpiUtMutexInitialize ();
if (ACPI_FAILURE (Status))
{
return -1;
}
AcpiCmInitGlobals ();
AcpiCmMutexInitialize ();
AcpiNsRootInitialize ();
Status = AcpiNsRootInitialize ();
if (ACPI_FAILURE (Status))
{
return -1;
}
/* Build the parse tree */
/* This is where the disassembly happens */
AslCompilerparse();
AcpiGbl_DbOpt_disasm = TRUE;
Status = AdAmlDisassemble (AslToFile,
Gbl_Files[ASL_FILE_INPUT].Filename,
Gbl_OutputFilenamePrefix,
&Gbl_Files[ASL_FILE_INPUT].Filename,
Gbl_GetAllTables);
if (ACPI_FAILURE (Status))
{
return -1;
}
/* Generate AML opcodes corresponding to the parse tokens */
DbgPrint ("\nGenerating AML opcodes\n\n");
TgWalkParseTree (ASL_WALK_VISIT_UPWARD, NULL, CgAmlOpcodeWalk, NULL);
/* Calculate all AML package lengths */
DbgPrint ("\nGenerating Package lengths\n\n");
TgWalkParseTree (ASL_WALK_VISIT_UPWARD, NULL, LnPackageLengthWalk, NULL);
/* Semantic error checking */
AnalysisWalkInfo.MethodStack = NULL;
DbgPrint ("\nSemantic analysis\n\n");
TgWalkParseTree (ASL_WALK_VISIT_TWICE, AnSemanticAnalysisWalkBegin,
AnSemanticAnalysisWalkEnd, &AnalysisWalkInfo);
/* Namespace loading */
LdLoadNamespace ();
/* Namespace lookup */
LkCrossReferenceNamespace ();
/* Calculate all AML package lengths */
DbgPrint ("\nGenerating Package lengths\n\n");
TgWalkParseTree (ASL_WALK_VISIT_UPWARD, NULL, LnInitLengthsWalk, NULL);
TgWalkParseTree (ASL_WALK_VISIT_UPWARD, NULL, LnPackageLengthWalk, NULL);
/*
* Gbl_Files[ASL_FILE_INPUT].Filename was replaced with the
* .DSL disassembly file, which can now be compiled if requested
*/
if (DoCompile)
{
AcpiOsPrintf ("\nCompiling \"%s\"\n",
Gbl_Files[ASL_FILE_INPUT].Filename);
}
}
/*
* ASL Compilation (Optional)
* Now that the input is parsed, we can open the AML output file.
* Note: by default, the name of this file comes from the table descriptor
* within the input file.
*/
if (DoCompile)
Status = FlOpenAmlOutputFile (Gbl_InputFilename);
if (ACPI_FAILURE (Status))
{
/*
* If -p not specified, we will use the input filename as the
* output filename prefix
*/
Status = FlSplitInputPathname (Gbl_Files[ASL_FILE_INPUT].Filename,
&Gbl_DirectoryPath, &Prefix);
if (ACPI_FAILURE (Status))
{
return -1;
}
if (Gbl_UseDefaultAmlFilename)
{
Gbl_OutputFilenamePrefix = Prefix;
}
/* ACPI CA subsystem initialization (Must be re-initialized) */
Status = AcpiOsInitialize ();
AcpiUtInitGlobals ();
Status = AcpiUtMutexInitialize ();
if (ACPI_FAILURE (Status))
{
return -1;
}
Status = AcpiNsRootInitialize ();
if (ACPI_FAILURE (Status))
{
return -1;
}
Status = CmDoCompile ();
AePrintErrorLog (stderr);
return -1;
}
return (0);
/* Code generation - emit the AML */
CgGenerateAmlOutput ();
AePrintErrorLog (stderr);
if (Gbl_DebugFlag)
{
/* Print to stdout */
AePrintErrorLog (stdout);
}
/* Dump the AML as hex if requested */
LsDoHexOutput ();
/* Dump the namespace to the .nsp file if requested */
LsDisplayNamespace ();
/* Close all open files */
FlCloseListingFile ();
FlCloseSourceOutputFile ();
FlCloseHexOutputFile ();
fclose (Gbl_OutputAmlFile);
if ((AslGbl_ExceptionCount[ASL_ERROR] > 0) && (!Gbl_IgnoreErrors))
{
unlink (Gbl_OutputFilename);
}
UtDisplaySummary ();
return 0;
}

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff