[BACK]Return to aslstartup.c CVS log [TXT][DIR] Up to [cvs.NetBSD.org] / src / sys / external / bsd / acpica / dist / compiler

Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.

Diff for /src/sys/external/bsd/acpica/dist/compiler/aslstartup.c between version 1.1.1.2 and 1.1.1.2.20.2

version 1.1.1.2, 2011/02/17 10:01:01 version 1.1.1.2.20.2, 2017/12/03 11:37:39
Line 1 
Line 1 
   
 /******************************************************************************  /******************************************************************************
  *   *
  * Module Name: aslstartup - Compiler startup routines, called from main   * Module Name: aslstartup - Compiler startup routines, called from main
Line 6 
Line 5 
  *****************************************************************************/   *****************************************************************************/
   
 /*  /*
  * Copyright (C) 2000 - 2011, Intel Corp.   * Copyright (C) 2000 - 2017, Intel Corp.
  * All rights reserved.   * All rights reserved.
  *   *
  * Redistribution and use in source and binary forms, with or without   * Redistribution and use in source and binary forms, with or without
Line 42 
Line 41 
  * POSSIBILITY OF SUCH DAMAGES.   * POSSIBILITY OF SUCH DAMAGES.
  */   */
   
   
 #include "aslcompiler.h"  #include "aslcompiler.h"
 #include "actables.h"  #include "actables.h"
   #include "acdisasm.h"
 #include "acapps.h"  #include "acapps.h"
   #include "acconvert.h"
   
 #define _COMPONENT          ACPI_COMPILER  #define _COMPONENT          ACPI_COMPILER
         ACPI_MODULE_NAME    ("aslstartup")          ACPI_MODULE_NAME    ("aslstartup")
   
   
 #define ASL_MAX_FILES   256  
 static char             *FileList[ASL_MAX_FILES];  
 static BOOLEAN          AslToFile = TRUE;  
   
   
 /* Local prototypes */  /* Local prototypes */
   
 static char **  
 AsDoWildcard (  
     char                    *DirectoryPathname,  
     char                    *FileSpecifier);  
   
 static UINT8  static UINT8
 AslDetectSourceFileType (  AslDetectSourceFileType (
     ASL_FILE_INFO           *Info);      ASL_FILE_INFO           *Info);
   
   static ACPI_STATUS
   AslDoDisassembly (
       void);
   
   
   /* Globals */
   
   static BOOLEAN          AslToFile = TRUE;
   
   
 /*******************************************************************************  /*******************************************************************************
  *   *
Line 90  AslInitializeGlobals (
Line 89  AslInitializeGlobals (
   
     /* Init compiler globals */      /* Init compiler globals */
   
       Gbl_SyntaxError = 0;
     Gbl_CurrentColumn = 0;      Gbl_CurrentColumn = 0;
     Gbl_CurrentLineNumber = 1;      Gbl_CurrentLineNumber = 1;
     Gbl_LogicalLineNumber = 1;      Gbl_LogicalLineNumber = 1;
     Gbl_CurrentLineOffset = 0;      Gbl_CurrentLineOffset = 0;
     Gbl_InputFieldCount = 0;      Gbl_InputFieldCount = 0;
       Gbl_InputByteCount = 0;
       Gbl_NsLookupCount = 0;
     Gbl_LineBufPtr = Gbl_CurrentLineBuffer;      Gbl_LineBufPtr = Gbl_CurrentLineBuffer;
   
     Gbl_ErrorLog = NULL;      Gbl_ErrorLog = NULL;
Line 102  AslInitializeGlobals (
Line 104  AslInitializeGlobals (
     Gbl_Signature = NULL;      Gbl_Signature = NULL;
     Gbl_FileType = 0;      Gbl_FileType = 0;
   
       TotalExecutableOpcodes = 0;
       TotalNamedObjects = 0;
       TotalKeywords = 0;
       TotalParseNodes = 0;
       TotalMethods = 0;
       TotalAllocations = 0;
       TotalAllocated = 0;
       TotalFolds = 0;
   
     AslGbl_NextEvent = 0;      AslGbl_NextEvent = 0;
     for (i = 0; i < ASL_NUM_REPORT_LEVELS; i++)      for (i = 0; i < ASL_NUM_REPORT_LEVELS; i++)
     {      {
         Gbl_ExceptionCount[i] = 0;          Gbl_ExceptionCount[i] = 0;
     }      }
   
     Gbl_Files[ASL_FILE_AML_OUTPUT].Filename = NULL;      for (i = ASL_FILE_INPUT; i <= ASL_MAX_FILE_TYPE; i++)
     Gbl_Files[ASL_FILE_AML_OUTPUT].Handle = NULL;      {
           Gbl_Files[i].Handle = NULL;
           Gbl_Files[i].Filename = NULL;
       }
   
     Gbl_Files[ASL_FILE_SOURCE_OUTPUT].Filename = NULL;      if (Gbl_CaptureComments)
     Gbl_Files[ASL_FILE_SOURCE_OUTPUT].Handle = NULL;      {
           Gbl_CommentState.SpacesBefore          = 0;
           Gbl_CommentState.CommentType           = 1;
           Gbl_CommentState.LatestParseOp          = NULL;
           Gbl_CommentState.ParsingParenBraceNode = NULL;
           Gbl_CommentState.CaptureComments       = TRUE;
       }
 }  }
   
   
 /******************************************************************************  /*******************************************************************************
  *   *
  * FUNCTION:    AsDoWildcard   * FUNCTION:    AslDetectSourceFileType
  *   *
  * PARAMETERS:  None   * PARAMETERS:  Info            - Name/Handle for the file (must be open)
  *   *
  * RETURN:      None   * RETURN:      File Type
  *   *
  * DESCRIPTION: Process files via wildcards. This function is for the Windows   * DESCRIPTION: Determine the type of the input file. Either binary (contains
  *              case only.   *              non-ASCII characters), ASL file, or an ACPI Data Table file.
  *   *
  ******************************************************************************/   ******************************************************************************/
   
 static char **  static UINT8
 AsDoWildcard (  AslDetectSourceFileType (
     char                    *DirectoryPathname,      ASL_FILE_INFO           *Info)
     char                    *FileSpecifier)  
 {  {
 #ifdef WIN32      char                    *FileChar;
     void                    *DirInfo;      UINT8                   Type = ASL_INPUT_TYPE_ASCII_DATA; /* default */
     char                    *Filename;      ACPI_STATUS             Status;
     int                     FileCount;  
   
   
     FileCount = 0;  
   
     /* Open parent directory */      /* Check for 100% ASCII source file (comments are ignored) */
   
     DirInfo = AcpiOsOpenDirectory (DirectoryPathname, FileSpecifier, REQUEST_FILE_ONLY);      Status = FlIsFileAsciiSource (Info->Filename, FALSE);
     if (!DirInfo)      if (ACPI_SUCCESS (Status))
     {      {
         /* Either the directory of file does not exist */          /*
            * File contains ASCII source code. Determine if this is an ASL
            * file or an ACPI data table file.
            */
           while (fgets (Gbl_CurrentLineBuffer, Gbl_LineBufferSize, Info->Handle))
           {
               /* Uppercase the buffer for caseless compare */
   
         Gbl_Files[ASL_FILE_INPUT].Filename = FileSpecifier;              FileChar = Gbl_CurrentLineBuffer;
         FlFileError (ASL_FILE_INPUT, ASL_MSG_OPEN);              while (*FileChar)
         AslAbort ();              {
                   *FileChar = (char) toupper ((int) *FileChar);
                   FileChar++;
               }
   
               /* Presence of "DefinitionBlock" indicates actual ASL code */
   
               if (strstr (Gbl_CurrentLineBuffer, "DEFINITIONBLOCK"))
               {
                   /* Appears to be an ASL file */
   
                   Type = ASL_INPUT_TYPE_ASCII_ASL;
                   goto Cleanup;
               }
           }
   
           /* Appears to be an ASCII data table source file */
   
           Type = ASL_INPUT_TYPE_ASCII_DATA;
           goto Cleanup;
     }      }
   
     /* Process each file that matches the wildcard specification */      /* We have some sort of binary table, check for valid ACPI table */
   
     while ((Filename = AcpiOsGetNextFilename (DirInfo)))      fseek (Info->Handle, 0, SEEK_SET);
     {  
         /* Add the filename to the file list */  
   
         FileList[FileCount] = AcpiOsAllocate (strlen (Filename) + 1);      Status = AcValidateTableHeader (Info->Handle, 0);
         strcpy (FileList[FileCount], Filename);      if (ACPI_SUCCESS (Status))
         FileCount++;      {
           fprintf (stderr,
               "Binary file appears to be a valid ACPI table, disassembling\n");
   
         if (FileCount >= ASL_MAX_FILES)          Type = ASL_INPUT_TYPE_BINARY_ACPI_TABLE;
         {          goto Cleanup;
             printf ("Max files reached\n");      }
             FileList[0] = NULL;      else
             return (FileList);      {
         }          fprintf (stderr,
               "Binary file does not contain a valid ACPI table\n");
     }      }
   
     /* Cleanup */      Type = ASL_INPUT_TYPE_BINARY;
   
     AcpiOsCloseDirectory (DirInfo);  
     FileList[FileCount] = NULL;  
     return (FileList);  
   
 #else  Cleanup:
     /*  
      * Linux/Unix cases - Wildcards are expanded by the shell automatically.      /* Must seek back to the start of the file */
      * Just return the filename in a null terminated list  
      */  
     FileList[0] = AcpiOsAllocate (strlen (FileSpecifier) + 1);  
     strcpy (FileList[0], FileSpecifier);  
     FileList[1] = NULL;  
   
     return (FileList);      fseek (Info->Handle, 0, SEEK_SET);
 #endif      return (Type);
 }  }
   
   
 /*******************************************************************************  /*******************************************************************************
  *   *
  * FUNCTION:    AslDetectSourceFileType   * FUNCTION:    AslDoDisassembly
  *   *
  * PARAMETERS:  Info            - Name/Handle for the file (must be open)   * PARAMETERS:  None
  *   *
  * RETURN:      File Type   * RETURN:      Status
  *   *
  * DESCRIPTION: Determine the type of the input file. Either binary (contains   * DESCRIPTION: Initiate AML file disassembly. Uses ACPICA subsystem to build
  *              non-ASCII characters), ASL file, or an ACPI Data Table file.   *              namespace.
  *   *
  ******************************************************************************/   ******************************************************************************/
   
 static UINT8  static ACPI_STATUS
 AslDetectSourceFileType (  AslDoDisassembly (
     ASL_FILE_INFO           *Info)      void)
 {  {
     char                    *FileChar;  
     UINT8                   Type;  
     ACPI_STATUS             Status;      ACPI_STATUS             Status;
   
   
     /* Check for 100% ASCII source file (comments are ignored) */      /* ACPICA subsystem initialization */
   
     Status = FlCheckForAscii (Info);      Status = AdInitialize ();
     if (ACPI_FAILURE (Status))      if (ACPI_FAILURE (Status))
     {      {
         printf ("Non-ascii input file - %s\n", Info->Filename);          return (Status);
         Type = ASL_INPUT_TYPE_BINARY;  
         goto Cleanup;  
     }      }
   
     /*      Status = AcpiAllocateRootTable (4);
      * File is ASCII. Determine if this is an ASL file or an ACPI data      if (ACPI_FAILURE (Status))
      * table file.  
      */  
     while (fgets (Gbl_CurrentLineBuffer, ASL_LINE_BUFFER_SIZE, Info->Handle))  
     {      {
         /* Uppercase the buffer for caseless compare */          AcpiOsPrintf ("Could not initialize ACPI Table Manager, %s\n",
               AcpiFormatException (Status));
           return (Status);
       }
   
         FileChar = Gbl_CurrentLineBuffer;      /* Handle additional output files for disassembler */
         while (*FileChar)  
         {  
             *FileChar = (char) toupper ((int) *FileChar);  
             FileChar++;  
         }  
   
         /* Presence of "DefinitionBlock" indicates actual ASL code */      Gbl_FileType = ASL_INPUT_TYPE_BINARY_ACPI_TABLE;
       Status = FlOpenMiscOutputFiles (Gbl_OutputFilenamePrefix);
   
         if (strstr (Gbl_CurrentLineBuffer, "DEFINITIONBLOCK"))      /* This is where the disassembly happens */
         {  
             /* Appears to be an ASL file */  
   
             Type = ASL_INPUT_TYPE_ASCII_ASL;      AcpiGbl_DmOpt_Disasm = TRUE;
             goto Cleanup;      Status = AdAmlDisassemble (AslToFile,
         }          Gbl_Files[ASL_FILE_INPUT].Filename, Gbl_OutputFilenamePrefix,
           &Gbl_Files[ASL_FILE_INPUT].Filename);
       if (ACPI_FAILURE (Status))
       {
           return (Status);
     }      }
   
     /* Not an ASL source file, default to a data table source file */      /* Check if any control methods were unresolved */
   
     Type = ASL_INPUT_TYPE_ASCII_DATA;      AcpiDmUnresolvedWarning (0);
   
 Cleanup:      /* Shutdown compiler and ACPICA subsystem */
   
     /* Must seek back to the start of the file */      AeClearErrorLog ();
       (void) AcpiTerminate ();
   
     fseek (Info->Handle, 0, SEEK_SET);      /*
     return (Type);       * Gbl_Files[ASL_FILE_INPUT].Filename was replaced with the
        * .DSL disassembly file, which can now be compiled if requested
        */
       if (Gbl_DoCompile)
       {
           AcpiOsPrintf ("\nCompiling \"%s\"\n",
               Gbl_Files[ASL_FILE_INPUT].Filename);
           return (AE_CTRL_CONTINUE);
       }
   
       /* No need to free the filename string */
   
       Gbl_Files[ASL_FILE_INPUT].Filename = NULL;
   
       UtDeleteLocalCaches ();
       return (AE_OK);
 }  }
   
   
Line 282  AslDoOneFile (
Line 326  AslDoOneFile (
     ACPI_STATUS             Status;      ACPI_STATUS             Status;
   
   
     Gbl_Files[ASL_FILE_INPUT].Filename = Filename;      /* Re-initialize "some" compiler/preprocessor globals */
   
     /* Re-initialize "some" compiler globals */  
   
     AslInitializeGlobals ();      AslInitializeGlobals ();
       PrInitializeGlobals ();
   
     /*      /*
      * AML Disassembly (Optional)       * Extract the directory path. This path is used for possible include
        * files and the optional AML filename embedded in the input file
        * DefinitionBlock declaration.
      */       */
     if (Gbl_DisasmFlag || Gbl_GetAllTables)      Status = FlSplitInputPathname (Filename, &Gbl_DirectoryPath, NULL);
       if (ACPI_FAILURE (Status))
     {      {
         /* ACPICA subsystem initialization */          return (Status);
       }
   
         Status = AdInitialize ();      /* Take a copy of the input filename, convert any backslashes */
         if (ACPI_FAILURE (Status))  
         {  
             return (Status);  
         }  
   
         Status = AcpiAllocateRootTable (4);      Gbl_Files[ASL_FILE_INPUT].Filename =
         if (ACPI_FAILURE (Status))          UtLocalCacheCalloc (strlen (Filename) + 1);
         {  
             AcpiOsPrintf ("Could not initialize ACPI Table Manager, %s\n",  
                 AcpiFormatException (Status));  
             return (Status);  
         }  
   
         /* This is where the disassembly happens */      strcpy (Gbl_Files[ASL_FILE_INPUT].Filename, Filename);
       UtConvertBackslashes (Gbl_Files[ASL_FILE_INPUT].Filename);
   
         AcpiGbl_DbOpt_disasm = TRUE;      /*
         Status = AdAmlDisassemble (AslToFile,       * AML Disassembly (Optional)
                     Gbl_Files[ASL_FILE_INPUT].Filename,       */
                     Gbl_OutputFilenamePrefix,      if (AcpiGbl_DisasmFlag)
                     &Gbl_Files[ASL_FILE_INPUT].Filename,      {
                     Gbl_GetAllTables);          Status = AslDoDisassembly ();
         if (ACPI_FAILURE (Status))          if (Status != AE_CTRL_CONTINUE)
         {          {
             return (Status);              return (Status);
         }          }
   
         /* Shutdown compiler and ACPICA subsystem */  
   
         AeClearErrorLog ();  
         (void) AcpiTerminate ();  
   
         /*  
          * Gbl_Files[ASL_FILE_INPUT].Filename was replaced with the  
          * .DSL disassembly file, which can now be compiled if requested  
          */  
         if (Gbl_DoCompile)  
         {  
             AcpiOsPrintf ("\nCompiling \"%s\"\n",  
                 Gbl_Files[ASL_FILE_INPUT].Filename);  
         }  
         else  
         {  
             Gbl_Files[ASL_FILE_INPUT].Filename = NULL;  
             return (AE_OK);  
         }  
     }      }
   
     /*      /*
Line 354  AslDoOneFile (
Line 373  AslDoOneFile (
         return (AE_ERROR);          return (AE_ERROR);
     }      }
   
       Gbl_OriginalInputFileSize = FlGetFileSize (ASL_FILE_INPUT);
   
     /* Determine input file type */      /* Determine input file type */
   
     Gbl_FileType = AslDetectSourceFileType (&Gbl_Files[ASL_FILE_INPUT]);      Gbl_FileType = AslDetectSourceFileType (&Gbl_Files[ASL_FILE_INPUT]);
Line 392  AslDoOneFile (
Line 413  AslDoOneFile (
     case ASL_INPUT_TYPE_ASCII_DATA:      case ASL_INPUT_TYPE_ASCII_DATA:
   
         Status = DtDoCompile ();          Status = DtDoCompile ();
           if (ACPI_FAILURE (Status))
           {
               return (Status);
           }
   
         if (Gbl_Signature)          if (Gbl_Signature)
         {          {
             ACPI_FREE (Gbl_Signature);  
             Gbl_Signature = NULL;              Gbl_Signature = NULL;
         }          }
   
           /* Check if any errors occurred during compile */
   
           Status = AslCheckForErrorExit ();
           if (ACPI_FAILURE (Status))
           {
               return (Status);
           }
   
           /* Cleanup (for next source file) and exit */
   
         AeClearErrorLog ();          AeClearErrorLog ();
           PrTerminatePreprocessor ();
         return (Status);          return (Status);
   
     /*      /*
      * ASL Compilation (Optional)       * ASL Compilation
      */       */
     case ASL_INPUT_TYPE_ASCII_ASL:      case ASL_INPUT_TYPE_ASCII_ASL:
   
Line 414  AslDoOneFile (
Line 450  AslDoOneFile (
             return (Status);              return (Status);
         }          }
   
         Status = CmDoCompile ();          (void) CmDoCompile ();
         (void) AcpiTerminate ();          (void) AcpiTerminate ();
   
         /*          /* Check if any errors occurred during compile */
          * Return non-zero exit code if there have been errors, unless the  
          * global ignore error flag has been set          Status = AslCheckForErrorExit ();
          */          if (ACPI_FAILURE (Status))
         if ((Gbl_ExceptionCount[ASL_ERROR] > 0) && (!Gbl_IgnoreErrors))  
         {          {
             return (AE_ERROR);              return (Status);
         }          }
   
           /* Cleanup (for next source file) and exit */
   
         AeClearErrorLog ();          AeClearErrorLog ();
           PrTerminatePreprocessor ();
   
           /* ASL-to-ASL+ conversion - Perform immediate disassembly */
   
           if (Gbl_DoAslConversion)
           {
               /*
                * New input file is the output AML file from above.
                * New output is from the input ASL file from above.
                */
               Gbl_OutputFilenamePrefix = Gbl_Files[ASL_FILE_INPUT].Filename;
           CvDbgPrint ("OUTPUTFILENAME: %s\n", Gbl_OutputFilenamePrefix);
               Gbl_Files[ASL_FILE_INPUT].Filename =
                   Gbl_Files[ASL_FILE_AML_OUTPUT].Filename;
               AcpiGbl_DisasmFlag = TRUE;
               fprintf (stderr, "\n");
               AslDoDisassembly ();
   
               /* delete the AML file. This AML file should never be utilized by AML interpreters. */
   
               FlDeleteFile (ASL_FILE_AML_OUTPUT);
           }
   
         return (AE_OK);          return (AE_OK);
   
       /*
        * Binary ACPI table was auto-detected, disassemble it
        */
       case ASL_INPUT_TYPE_BINARY_ACPI_TABLE:
   
           /* We have what appears to be an ACPI table, disassemble it */
   
           FlCloseFile (ASL_FILE_INPUT);
           Gbl_DoCompile = FALSE;
           AcpiGbl_DisasmFlag = TRUE;
           Status = AslDoDisassembly ();
           return (Status);
   
       /* Unknown binary table */
   
     case ASL_INPUT_TYPE_BINARY:      case ASL_INPUT_TYPE_BINARY:
   
         AePrintErrorLog (ASL_FILE_STDERR);          AePrintErrorLog (ASL_FILE_STDERR);
         return (AE_ERROR);          return (AE_ERROR);
   
     default:      default:
   
         printf ("Unknown file type %X\n", Gbl_FileType);          printf ("Unknown file type %X\n", Gbl_FileType);
         return (AE_ERROR);          return (AE_ERROR);
     }      }
Line 443  AslDoOneFile (
Line 519  AslDoOneFile (
   
 /*******************************************************************************  /*******************************************************************************
  *   *
  * FUNCTION:    AslDoOnePathname   * FUNCTION:    AslCheckForErrorExit
  *   *
  * PARAMETERS:  Pathname            - Full pathname, possibly with wildcards   * PARAMETERS:  None. Examines global exception count array
  *   *
  * RETURN:      Status   * RETURN:      Status
  *   *
  * DESCRIPTION: Process one pathname, possible terminated with a wildcard   * DESCRIPTION: Determine if compiler should abort with error status
  *              specification. If a wildcard, it is expanded and the multiple  
  *              files are processed.  
  *   *
  ******************************************************************************/   ******************************************************************************/
   
 ACPI_STATUS  ACPI_STATUS
 AslDoOnePathname (  AslCheckForErrorExit (
     char                    *Pathname,      void)
     ASL_PATHNAME_CALLBACK   PathCallback)  
 {  {
     ACPI_STATUS             Status = AE_OK;  
     char                    **WildcardList;  
     char                    *Filename;  
     char                    *FullPathname;  
   
   
     /* Split incoming path into a directory/filename combo */      /*
        * Return non-zero exit code if there have been errors, unless the
     Status = FlSplitInputPathname (Pathname, &Gbl_DirectoryPath, &Filename);       * global ignore error flag has been set
     if (ACPI_FAILURE (Status))       */
     {      if (!Gbl_IgnoreErrors)
         return (Status);  
     }  
   
     /* Expand possible wildcard into a file list (Windows/DOS only) */  
   
     WildcardList = AsDoWildcard (Gbl_DirectoryPath, Filename);  
     while (*WildcardList)  
     {      {
         FullPathname = ACPI_ALLOCATE (          if (Gbl_ExceptionCount[ASL_ERROR] > 0)
             strlen (Gbl_DirectoryPath) + strlen (*WildcardList) + 1);  
   
         /* Construct a full path to the file */  
   
         strcpy (FullPathname, Gbl_DirectoryPath);  
         strcat (FullPathname, *WildcardList);  
   
         /*  
          * If -p not specified, we will use the input filename as the  
          * output filename prefix  
          */  
         if (Gbl_UseDefaultAmlFilename)  
         {          {
             Gbl_OutputFilenamePrefix = FullPathname;              return (AE_ERROR);
         }          }
   
         /* Save status from all compiles */          /* Optionally treat warnings as errors */
   
         Status |= (*PathCallback) (FullPathname);  
   
         ACPI_FREE (FullPathname);          if (Gbl_WarningsAsErrors)
         ACPI_FREE (*WildcardList);          {
         *WildcardList = NULL;              if ((Gbl_ExceptionCount[ASL_WARNING] > 0)  ||
         WildcardList++;                  (Gbl_ExceptionCount[ASL_WARNING2] > 0) ||
                   (Gbl_ExceptionCount[ASL_WARNING3] > 0))
               {
                   return (AE_ERROR);
               }
           }
     }      }
   
     ACPI_FREE (Gbl_DirectoryPath);      return (AE_OK);
     ACPI_FREE (Filename);  
     return (Status);  
 }  }
   

Legend:
Removed from v.1.1.1.2  
changed lines
  Added in v.1.1.1.2.20.2

CVSweb <webmaster@jp.NetBSD.org>