Skip to content

Commit

Permalink
iASL: add ASL conversion tool
Browse files Browse the repository at this point in the history
The key feature of this utility is that the original comments within
the input ASL files are preserved during the conversion process, and
included within the converted ASL+ file -- thus creating a transparent
conversion of existing ASL files to ASL+ (ASL 2.0)
  • Loading branch information
acpibob committed Feb 24, 2017
1 parent 20741c9 commit c04d310
Show file tree
Hide file tree
Showing 48 changed files with 3,807 additions and 105 deletions.
12 changes: 12 additions & 0 deletions generate/msvc9/AslCompiler.vcproj
Expand Up @@ -1019,6 +1019,18 @@
RelativePath="..\..\source\compiler\aslxrefout.c"
>
</File>
<File
RelativePath="..\..\source\compiler\cvcompiler.c"
>
</File>
<File
RelativePath="..\..\source\compiler\cvdisasm.c"
>
</File>
<File
RelativePath="..\..\source\compiler\cvparser.c"
>
</File>
</Filter>
<Filter
Name="Compiler Lexers"
Expand Down
3 changes: 3 additions & 0 deletions generate/unix/iasl/Makefile
Expand Up @@ -105,6 +105,9 @@ OBJECTS = \
$(OBJDIR)/aslwalks.o\
$(OBJDIR)/aslxref.o\
$(OBJDIR)/aslxrefout.o\
$(OBJDIR)/cvcompiler.o\
$(OBJDIR)/cvdisasm.o\
$(OBJDIR)/cvparser.o\
$(OBJDIR)/cmfsize.o\
$(OBJDIR)/dbfileio.o\
$(OBJDIR)/dmbuffer.o\
Expand Down
25 changes: 25 additions & 0 deletions source/common/adisasm.c
Expand Up @@ -398,6 +398,21 @@ AdDisassembleOneTable (
ACPI_OWNER_ID OwnerId;


#ifdef ACPI_ASL_COMPILER

/*
* For ASL-/ASL+ converter: replace the temporary "XXXX"
* table signature with the original. This "XXXX" makes
* it harder for the AML interpreter to run the badaml
* (.xxx) file produced from the converter in case if
* it fails to get deleted.
*/
if (Gbl_CaptureComments)
{
strncpy (Table->Signature, AcpiGbl_TableSig, 4);
}
#endif

/* ForceAmlDisassembly means to assume the table contains valid AML */

if (!AcpiGbl_ForceAmlDisassembly && !AcpiUtIsAmlTable (Table))
Expand Down Expand Up @@ -547,6 +562,7 @@ AdReparseOneTable (
ACPI_OWNER_ID OwnerId)
{
ACPI_STATUS Status;
ACPI_COMMENT_ADDR_NODE *AddrListHead;


fprintf (stderr,
Expand Down Expand Up @@ -580,6 +596,15 @@ AdReparseOneTable (

AcpiDmAddExternalsToNamespace ();

/* For -ca option: clear the list of comment addresses. */

while (AcpiGbl_CommentAddrListHead)
{
AddrListHead= AcpiGbl_CommentAddrListHead;
AcpiGbl_CommentAddrListHead = AcpiGbl_CommentAddrListHead->Next;
AcpiOsFree(AddrListHead);
}

/* Parse the table again. No need to reload it, however */

Status = AdParseTable (Table, NULL, FALSE, FALSE);
Expand Down
22 changes: 22 additions & 0 deletions source/common/dmtables.c
Expand Up @@ -119,6 +119,8 @@
#include "actables.h"
#include "acparser.h"
#include "acapps.h"
#include "acmacros.h"
#include "acconvert.h"


#define _COMPONENT ACPI_TOOLS
Expand Down Expand Up @@ -273,6 +275,14 @@ AdCreateTableHeader (
AcpiOsPrintf (" * Compiler Version 0x%8.8X (%u)\n", Table->AslCompilerRevision, Table->AslCompilerRevision);
AcpiOsPrintf (" */\n");

/*
* Print comments that come before this definition block.
*/
if (Gbl_CaptureComments)
{
ASL_CV_PRINT_ONE_COMMENT(AcpiGbl_ParseOpRoot,AML_COMMENT_STANDARD, NULL, 0);
}

/*
* Open the ASL definition block.
*
Expand Down Expand Up @@ -460,6 +470,7 @@ AdParseTable (

AmlLength = Table->Length - sizeof (ACPI_TABLE_HEADER);
AmlStart = ((UINT8 *) Table + sizeof (ACPI_TABLE_HEADER));
ASL_CV_INIT_FILETREE(Table, AmlStart, AmlLength);

/* Create the root object */

Expand All @@ -469,6 +480,17 @@ AdParseTable (
return (AE_NO_MEMORY);
}

#ifdef ACPI_ASL_COMPILER
if (Gbl_CaptureComments)
{
AcpiGbl_ParseOpRoot->Common.CvFilename = AcpiGbl_FileTreeRoot->Filename;
}
else
{
AcpiGbl_ParseOpRoot->Common.CvFilename = NULL;
}
#endif

/* Create and initialize a new walk state */

WalkState = AcpiDsCreateWalkState (0, AcpiGbl_ParseOpRoot, NULL, NULL);
Expand Down
101 changes: 88 additions & 13 deletions source/compiler/aslcodegen.c
Expand Up @@ -116,6 +116,7 @@
#include "aslcompiler.h"
#include "aslcompiler.y.h"
#include "amlcode.h"
#include "acconvert.h"

#define _COMPONENT ACPI_COMPILER
ACPI_MODULE_NAME ("aslcodegen")
Expand All @@ -128,12 +129,6 @@ CgAmlWriteWalk (
UINT32 Level,
void *Context);

static void
CgLocalWriteAmlData (
ACPI_PARSE_OBJECT *Op,
void *Buffer,
UINT32 Length);

static void
CgWriteAmlOpcode (
ACPI_PARSE_OBJECT *Op);
Expand Down Expand Up @@ -278,7 +273,7 @@ CgAmlWriteWalk (
*
******************************************************************************/

static void
void
CgLocalWriteAmlData (
ACPI_PARSE_OBJECT *Op,
void *Buffer,
Expand Down Expand Up @@ -333,6 +328,15 @@ CgWriteAmlOpcode (
return;
}

/*
* Before printing the bytecode, generate comment byte codes
* associated with this node.
*/
if (Gbl_CaptureComments)
{
CgWriteAmlComment(Op);
}

switch (Op->Asl.AmlOpcode)
{
case AML_UNASSIGNED_OPCODE:
Expand Down Expand Up @@ -488,6 +492,8 @@ CgWriteTableHeader (
ACPI_PARSE_OBJECT *Op)
{
ACPI_PARSE_OBJECT *Child;
UINT32 CommentLength;
ACPI_COMMENT_NODE *Current;


/* AML filename */
Expand All @@ -497,6 +503,21 @@ CgWriteTableHeader (
/* Signature */

Child = Child->Asl.Next;

/*
* For ASL-/ASL+ converter: replace the table signature with
* "XXXX" and save the original table signature. This results in an AML
* file with the signature "XXXX". The converter should remove this AML
* file. In the event where this AML file does not get deleted, the
* "XXXX" table signature prevents this AML file from running on the AML
* interpreter.
*/
if (Gbl_CaptureComments)
{
strncpy(AcpiGbl_TableSig, Child->Asl.Value.String, 4);
Child->Asl.Value.String = ACPI_SIG_XXXX;
}

strncpy (TableHeader.Signature, Child->Asl.Value.String, 4);

/* Revision */
Expand Down Expand Up @@ -538,6 +559,50 @@ CgWriteTableHeader (

TableHeader.Length = sizeof (ACPI_TABLE_HEADER) +
Op->Asl.AmlSubtreeLength;

/* Calculate the comment lengths for this definition block parseOp */

if (Gbl_CaptureComments)
{
CvDbgPrint ("Calculating comment lengths for %s in write header\n",
Op->Asl.ParseOpName);

/*
* Take the filename without extensions, add 3 for the new extension
* and another 3 for the a908 bytecode and null terminator.
*/
TableHeader.Length += strrchr (Gbl_ParseTreeRoot->Asl.Filename, '.')
- Gbl_ParseTreeRoot->Asl.Filename + 1 + 3 + 3;
Op->Asl.AmlSubtreeLength +=
strlen (Gbl_ParseTreeRoot->Asl.Filename) + 3;
CvDbgPrint (" Length: %lu\n",
strlen (Gbl_ParseTreeRoot->Asl.Filename) + 3);

if (Op->Asl.CommentList)
{
Current = Op->Asl.CommentList;
while (Current)
{
CommentLength = strlen (Current->Comment)+3;
CvDbgPrint ("Length of standard comment): %d\n", CommentLength);
CvDbgPrint (" Comment string: %s\n\n", Current->Comment);
TableHeader.Length += CommentLength;
Op->Asl.AmlSubtreeLength += CommentLength;
Current = Current->Next;
CvDbgPrint (" Length: %u\n", CommentLength);
}
}
if (Op->Asl.CloseBraceComment)
{
CommentLength = strlen (Op->Asl.CloseBraceComment)+3;
CvDbgPrint ("Length of inline comment +3: %d\n", CommentLength);
CvDbgPrint (" Comment string: %s\n\n", Op->Asl.CloseBraceComment);
TableHeader.Length += CommentLength;
Op->Asl.AmlSubtreeLength += CommentLength;
CvDbgPrint (" Length: %u\n", CommentLength);
}
}

TableHeader.Checksum = 0;

Op->Asl.FinalAmlOffset = ftell (Gbl_Files[ASL_FILE_AML_OUTPUT].Handle);
Expand All @@ -564,13 +629,13 @@ CgWriteTableHeader (

static void
CgUpdateHeader (
ACPI_PARSE_OBJECT *Op)
ACPI_PARSE_OBJECT *Op)
{
signed char Sum;
UINT32 i;
UINT32 Length;
UINT8 FileByte;
UINT8 Checksum;
signed char Sum;
UINT32 i;
UINT32 Length;
UINT8 FileByte;
UINT8 Checksum;


/* Calculate the checksum over the entire definition block */
Expand Down Expand Up @@ -652,6 +717,12 @@ CgWriteNode (
ASL_RESOURCE_NODE *Rnode;


/* Write all comments here. */
if (Gbl_CaptureComments)
{
CgWriteAmlComment(Op);
}

/* Always check for DEFAULT_ARG and other "Noop" nodes */
/* TBD: this may not be the best place for this check */

Expand Down Expand Up @@ -713,6 +784,10 @@ CgWriteNode (
case PARSEOP_DEFINITION_BLOCK:

CgWriteTableHeader (Op);
if (Gbl_CaptureComments)
{
CgWriteAmlDefBlockComment (Op);
}
break;

case PARSEOP_NAMESEG:
Expand Down
18 changes: 17 additions & 1 deletion source/compiler/aslcompile.c
Expand Up @@ -428,6 +428,18 @@ CmDoCompile (
NULL, &AnalysisWalkInfo);
UtEndEvent (Event);

/*
* ASL-/ASL+ converter: Gbl_ParseTreeRoot->CommentList contains the
* very last comment of a given ASL file because it's the last constructed
* node during compilation. We take the very last comment and save it in a
* global for it to be used by the disassembler.
*/
if (Gbl_CaptureComments)
{
AcpiGbl_LastListHead = Gbl_ParseTreeRoot->Asl.CommentList;
Gbl_ParseTreeRoot->Asl.CommentList = NULL;
}

/* Calculate all AML package lengths */

Event = UtBeginEvent ("Finish AML package length generation");
Expand Down Expand Up @@ -881,7 +893,11 @@ CmCleanupAndExit (

/* Final cleanup after compiling one file */

CmDeleteCaches ();
if (!Gbl_DoAslConversion)
{
CmDeleteCaches ();
}

}


Expand Down
16 changes: 16 additions & 0 deletions source/compiler/aslcompiler.h
Expand Up @@ -648,6 +648,12 @@ void
CgGenerateAmlOutput (
void);

void
CgLocalWriteAmlData (
ACPI_PARSE_OBJECT *Op,
void *Buffer,
UINT32 Length);


/*
* aslfile
Expand Down Expand Up @@ -1431,4 +1437,14 @@ ACPI_STATUS
DtCreateTemplates (
char **argv);


/*
* ASL/ASL+ converter debug
*/
void
CvDbgPrint (
char *Fmt,
...);


#endif /* __ASLCOMPILER_H */
5 changes: 3 additions & 2 deletions source/compiler/aslcompiler.l
Expand Up @@ -116,6 +116,7 @@

#include "aslcompiler.h"
#include "aslcompiler.y.h"
#include "acconvert.h"

#include <stdlib.h>
#include <string.h>
Expand All @@ -138,10 +139,10 @@ YYSTYPE AslCompilerlval;
static void
AslDoLineDirective (void);

static char
static BOOLEAN
AslDoComment (void);

static char
static BOOLEAN
AslDoCommentType2 (void);

static char
Expand Down

0 comments on commit c04d310

Please sign in to comment.