Annotation of src/sys/external/bsd/acpica/dist/compiler/aslstartup.c, Revision 1.1.1.14
1.1 jruoho 1: /******************************************************************************
2: *
3: * Module Name: aslstartup - Compiler startup routines, called from main
4: *
5: *****************************************************************************/
6:
1.1.1.2 jruoho 7: /*
1.1.1.14! christos 8: * Copyright (C) 2000 - 2019, Intel Corp.
1.1 jruoho 9: * All rights reserved.
10: *
1.1.1.2 jruoho 11: * Redistribution and use in source and binary forms, with or without
12: * modification, are permitted provided that the following conditions
13: * are met:
14: * 1. Redistributions of source code must retain the above copyright
15: * notice, this list of conditions, and the following disclaimer,
16: * without modification.
17: * 2. Redistributions in binary form must reproduce at minimum a disclaimer
18: * substantially similar to the "NO WARRANTY" disclaimer below
19: * ("Disclaimer") and any redistribution must be conditioned upon
20: * including a substantially similar Disclaimer requirement for further
21: * binary redistribution.
22: * 3. Neither the names of the above-listed copyright holders nor the names
23: * of any contributors may be used to endorse or promote products derived
24: * from this software without specific prior written permission.
25: *
26: * Alternatively, this software may be distributed under the terms of the
27: * GNU General Public License ("GPL") version 2 as published by the Free
28: * Software Foundation.
29: *
30: * NO WARRANTY
31: * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
32: * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
33: * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
34: * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
35: * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
36: * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
37: * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
38: * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
39: * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
40: * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
41: * POSSIBILITY OF SUCH DAMAGES.
42: */
1.1 jruoho 43:
44: #include "aslcompiler.h"
45: #include "actables.h"
1.1.1.3 christos 46: #include "acdisasm.h"
1.1 jruoho 47: #include "acapps.h"
1.1.1.9 christos 48: #include "acconvert.h"
1.1 jruoho 49:
50: #define _COMPONENT ACPI_COMPILER
51: ACPI_MODULE_NAME ("aslstartup")
52:
53:
54: /* Local prototypes */
55:
1.1.1.2 jruoho 56: static UINT8
1.1 jruoho 57: AslDetectSourceFileType (
58: ASL_FILE_INFO *Info);
59:
1.1.1.3 christos 60:
61: /* Globals */
62:
63: static BOOLEAN AslToFile = TRUE;
64:
1.1 jruoho 65:
66: /*******************************************************************************
67: *
68: * FUNCTION: AslInitializeGlobals
69: *
70: * PARAMETERS: None
71: *
72: * RETURN: None
73: *
74: * DESCRIPTION: Re-initialize globals needed to restart the compiler. This
75: * allows multiple files to be disassembled and/or compiled.
76: *
77: ******************************************************************************/
78:
1.1.1.2 jruoho 79: void
1.1 jruoho 80: AslInitializeGlobals (
81: void)
82: {
83: UINT32 i;
84:
85:
86: /* Init compiler globals */
87:
1.1.1.13 christos 88: AslGbl_SyntaxError = 0;
89: AslGbl_CurrentColumn = 0;
90: AslGbl_CurrentLineNumber = 1;
91: AslGbl_LogicalLineNumber = 1;
92: AslGbl_CurrentLineOffset = 0;
93: AslGbl_InputFieldCount = 0;
94: AslGbl_InputByteCount = 0;
95: AslGbl_NsLookupCount = 0;
96: AslGbl_LineBufPtr = AslGbl_CurrentLineBuffer;
97:
98: AslGbl_ErrorLog = NULL;
99: AslGbl_NextError = NULL;
100: AslGbl_Signature = NULL;
101: AslGbl_FileType = 0;
102:
103: AslGbl_TotalExecutableOpcodes = 0;
104: AslGbl_TotalNamedObjects = 0;
105: AslGbl_TotalKeywords = 0;
106: AslGbl_TotalParseNodes = 0;
107: AslGbl_TotalMethods = 0;
108: AslGbl_TotalAllocations = 0;
109: AslGbl_TotalAllocated = 0;
110: AslGbl_TotalFolds = 0;
1.1.1.3 christos 111:
1.1 jruoho 112: AslGbl_NextEvent = 0;
113: for (i = 0; i < ASL_NUM_REPORT_LEVELS; i++)
114: {
1.1.1.13 christos 115: AslGbl_ExceptionCount[i] = 0;
1.1 jruoho 116: }
117:
1.1.1.12 christos 118: if (AcpiGbl_CaptureComments)
1.1.1.9 christos 119: {
1.1.1.13 christos 120: AslGbl_CommentState.SpacesBefore = 0;
121: AslGbl_CommentState.CommentType = 1;
122: AslGbl_CommentState.LatestParseOp = NULL;
123: AslGbl_CommentState.ParsingParenBraceNode = NULL;
124: AslGbl_CommentState.CaptureComments = TRUE;
1.1.1.9 christos 125: }
1.1 jruoho 126: }
127:
128:
129: /*******************************************************************************
130: *
131: * FUNCTION: AslDetectSourceFileType
132: *
133: * PARAMETERS: Info - Name/Handle for the file (must be open)
134: *
135: * RETURN: File Type
136: *
137: * DESCRIPTION: Determine the type of the input file. Either binary (contains
138: * non-ASCII characters), ASL file, or an ACPI Data Table file.
139: *
140: ******************************************************************************/
141:
1.1.1.2 jruoho 142: static UINT8
1.1 jruoho 143: AslDetectSourceFileType (
144: ASL_FILE_INFO *Info)
145: {
146: char *FileChar;
1.1.1.7 christos 147: UINT8 Type = ASL_INPUT_TYPE_ASCII_DATA; /* default */
1.1 jruoho 148: ACPI_STATUS Status;
149:
150:
1.1.1.7 christos 151: /* Check for 100% ASCII source file (comments are ignored) */
1.1.1.3 christos 152:
1.1.1.7 christos 153: Status = FlIsFileAsciiSource (Info->Filename, FALSE);
1.1.1.3 christos 154: if (ACPI_SUCCESS (Status))
155: {
1.1.1.7 christos 156: /*
157: * File contains ASCII source code. Determine if this is an ASL
158: * file or an ACPI data table file.
159: */
1.1.1.13 christos 160: while (fgets (AslGbl_CurrentLineBuffer, AslGbl_LineBufferSize, Info->Handle))
1.1.1.7 christos 161: {
162: /* Uppercase the buffer for caseless compare */
1.1.1.3 christos 163:
1.1.1.13 christos 164: FileChar = AslGbl_CurrentLineBuffer;
1.1.1.7 christos 165: while (*FileChar)
166: {
167: *FileChar = (char) toupper ((int) *FileChar);
168: FileChar++;
169: }
1.1 jruoho 170:
1.1.1.7 christos 171: /* Presence of "DefinitionBlock" indicates actual ASL code */
1.1.1.3 christos 172:
1.1.1.13 christos 173: if (strstr (AslGbl_CurrentLineBuffer, "DEFINITIONBLOCK"))
1.1.1.7 christos 174: {
175: /* Appears to be an ASL file */
176:
177: Type = ASL_INPUT_TYPE_ASCII_ASL;
178: goto Cleanup;
179: }
1.1.1.3 christos 180: }
1.1 jruoho 181:
1.1.1.7 christos 182: /* Appears to be an ASCII data table source file */
1.1 jruoho 183:
1.1.1.7 christos 184: Type = ASL_INPUT_TYPE_ASCII_DATA;
185: goto Cleanup;
186: }
1.1 jruoho 187:
1.1.1.7 christos 188: /* We have some sort of binary table, check for valid ACPI table */
1.1 jruoho 189:
1.1.1.7 christos 190: fseek (Info->Handle, 0, SEEK_SET);
1.1 jruoho 191:
1.1.1.7 christos 192: Status = AcValidateTableHeader (Info->Handle, 0);
193: if (ACPI_SUCCESS (Status))
194: {
195: fprintf (stderr,
196: "Binary file appears to be a valid ACPI table, disassembling\n");
197:
198: Type = ASL_INPUT_TYPE_BINARY_ACPI_TABLE;
199: goto Cleanup;
1.1 jruoho 200: }
1.1.1.10 christos 201: else
202: {
203: fprintf (stderr,
204: "Binary file does not contain a valid ACPI table\n");
205: }
1.1 jruoho 206:
1.1.1.7 christos 207: Type = ASL_INPUT_TYPE_BINARY;
1.1 jruoho 208:
209:
210: Cleanup:
211:
212: /* Must seek back to the start of the file */
213:
214: fseek (Info->Handle, 0, SEEK_SET);
215: return (Type);
216: }
217:
218:
219: /*******************************************************************************
220: *
1.1.1.3 christos 221: * FUNCTION: AslDoDisassembly
222: *
223: * PARAMETERS: None
224: *
225: * RETURN: Status
226: *
227: * DESCRIPTION: Initiate AML file disassembly. Uses ACPICA subsystem to build
1.1.1.14! christos 228: * namespace. This function assumes that the ACPI subsystem has
! 229: * been initialized. The caller of the initialization will also
! 230: * terminate the ACPI subsystem.
1.1.1.3 christos 231: *
232: ******************************************************************************/
233:
1.1.1.14! christos 234: ACPI_STATUS
1.1.1.3 christos 235: AslDoDisassembly (
236: void)
237: {
238: ACPI_STATUS Status;
239:
240:
241: Status = AcpiAllocateRootTable (4);
242: if (ACPI_FAILURE (Status))
243: {
244: AcpiOsPrintf ("Could not initialize ACPI Table Manager, %s\n",
245: AcpiFormatException (Status));
246: return (Status);
247: }
248:
249: /* This is where the disassembly happens */
250:
1.1.1.7 christos 251: AcpiGbl_DmOpt_Disasm = TRUE;
1.1.1.3 christos 252: Status = AdAmlDisassemble (AslToFile,
1.1.1.13 christos 253: AslGbl_Files[ASL_FILE_INPUT].Filename, AslGbl_OutputFilenamePrefix,
254: &AslGbl_Files[ASL_FILE_INPUT].Filename);
1.1.1.3 christos 255: if (ACPI_FAILURE (Status))
256: {
257: return (Status);
258: }
259:
260: /* Check if any control methods were unresolved */
261:
262: AcpiDmUnresolvedWarning (0);
263:
1.1.1.14! christos 264: /* Clear Error log */
1.1.1.3 christos 265:
266: AeClearErrorLog ();
267:
268: /*
1.1.1.13 christos 269: * AslGbl_Files[ASL_FILE_INPUT].Filename was replaced with the
1.1.1.3 christos 270: * .DSL disassembly file, which can now be compiled if requested
271: */
1.1.1.13 christos 272: if (AslGbl_DoCompile)
1.1.1.3 christos 273: {
274: AcpiOsPrintf ("\nCompiling \"%s\"\n",
1.1.1.13 christos 275: AslGbl_Files[ASL_FILE_INPUT].Filename);
1.1.1.3 christos 276: return (AE_CTRL_CONTINUE);
277: }
278:
279: return (AE_OK);
280: }
281:
282:
283: /*******************************************************************************
284: *
1.1 jruoho 285: * FUNCTION: AslDoOneFile
286: *
287: * PARAMETERS: Filename - Name of the file
288: *
289: * RETURN: Status
290: *
291: * DESCRIPTION: Process a single file - either disassemble, compile, or both
292: *
293: ******************************************************************************/
294:
295: ACPI_STATUS
296: AslDoOneFile (
297: char *Filename)
298: {
299: ACPI_STATUS Status;
1.1.1.14! christos 300: UINT8 Event;
! 301: ASL_GLOBAL_FILE_NODE *FileNode;
1.1 jruoho 302:
303:
1.1.1.3 christos 304: /* Re-initialize "some" compiler/preprocessor globals */
1.1 jruoho 305:
306: AslInitializeGlobals ();
1.1.1.3 christos 307: PrInitializeGlobals ();
1.1 jruoho 308:
309: /*
1.1.1.3 christos 310: * Extract the directory path. This path is used for possible include
311: * files and the optional AML filename embedded in the input file
312: * DefinitionBlock declaration.
1.1 jruoho 313: */
1.1.1.13 christos 314: Status = FlSplitInputPathname (Filename, &AslGbl_DirectoryPath, NULL);
1.1.1.3 christos 315: if (ACPI_FAILURE (Status))
1.1 jruoho 316: {
1.1.1.3 christos 317: return (Status);
318: }
1.1 jruoho 319:
1.1.1.14! christos 320: /*
! 321: * There was an input file detected at this point. Each input ASL file is
! 322: * associated with one global file node consisting of the input file and
! 323: * all output files associated with it. This is useful when compiling
! 324: * multiple files in one command.
! 325: */
! 326: Status = FlInitOneFile(Filename);
! 327: if (ACPI_FAILURE (Status))
! 328: {
! 329: return (AE_ERROR);
! 330: }
! 331:
1.1.1.4 christos 332: /* Take a copy of the input filename, convert any backslashes */
333:
1.1.1.13 christos 334: AslGbl_Files[ASL_FILE_INPUT].Filename =
1.1.1.11 christos 335: UtLocalCacheCalloc (strlen (Filename) + 1);
1.1.1.4 christos 336:
1.1.1.13 christos 337: strcpy (AslGbl_Files[ASL_FILE_INPUT].Filename, Filename);
338: UtConvertBackslashes (AslGbl_Files[ASL_FILE_INPUT].Filename);
1.1 jruoho 339:
1.1.1.3 christos 340: /*
1.1 jruoho 341: * Open the input file. Here, this should be an ASCII source file,
342: * either an ASL file or a Data Table file
343: */
1.1.1.13 christos 344: Status = FlOpenInputFile (AslGbl_Files[ASL_FILE_INPUT].Filename);
1.1 jruoho 345: if (ACPI_FAILURE (Status))
346: {
347: AePrintErrorLog (ASL_FILE_STDERR);
348: return (AE_ERROR);
349: }
350:
1.1.1.14! christos 351: FileNode = FlGetCurrentFileNode();
! 352: if (!FileNode)
! 353: {
! 354: return (AE_ERROR);
! 355: }
! 356:
! 357: FileNode->OriginalInputFileSize = FlGetFileSize (ASL_FILE_INPUT);
1.1.1.6 christos 358:
1.1 jruoho 359: /* Determine input file type */
360:
1.1.1.13 christos 361: AslGbl_FileType = AslDetectSourceFileType (&AslGbl_Files[ASL_FILE_INPUT]);
362: if (AslGbl_FileType == ASL_INPUT_TYPE_BINARY)
1.1 jruoho 363: {
364: return (AE_ERROR);
365: }
366:
367: /*
368: * If -p not specified, we will use the input filename as the
369: * output filename prefix
370: */
1.1.1.13 christos 371: if (AslGbl_UseDefaultAmlFilename)
1.1 jruoho 372: {
1.1.1.13 christos 373: AslGbl_OutputFilenamePrefix = AslGbl_Files[ASL_FILE_INPUT].Filename;
1.1 jruoho 374: }
375:
1.1.1.14! christos 376: /*
! 377: * Open the output file. Note: by default, the name of this file comes from
! 378: * the table descriptor within the input file.
! 379: */
! 380: if (AslGbl_FileType == ASL_INPUT_TYPE_ASCII_ASL)
! 381: {
! 382: Event = UtBeginEvent ("Open AML output file");
! 383: Status = FlOpenAmlOutputFile (AslGbl_OutputFilenamePrefix);
! 384: UtEndEvent (Event);
! 385: if (ACPI_FAILURE (Status))
! 386: {
! 387: AePrintErrorLog (ASL_FILE_STDERR);
! 388: return (AE_ERROR);
! 389: }
! 390: }
! 391:
1.1 jruoho 392: /* Open the optional output files (listings, etc.) */
393:
1.1.1.13 christos 394: Status = FlOpenMiscOutputFiles (AslGbl_OutputFilenamePrefix);
1.1 jruoho 395: if (ACPI_FAILURE (Status))
396: {
397: AePrintErrorLog (ASL_FILE_STDERR);
398: return (AE_ERROR);
399: }
400:
401: /*
402: * Compilation of ASL source versus DataTable source uses different
403: * compiler subsystems
404: */
1.1.1.13 christos 405: switch (AslGbl_FileType)
1.1 jruoho 406: {
407: /*
408: * Data Table Compilation
409: */
410: case ASL_INPUT_TYPE_ASCII_DATA:
411:
412: Status = DtDoCompile ();
1.1.1.3 christos 413: if (ACPI_FAILURE (Status))
414: {
415: return (Status);
416: }
1.1 jruoho 417:
1.1.1.13 christos 418: if (AslGbl_Signature)
1.1 jruoho 419: {
1.1.1.13 christos 420: AslGbl_Signature = NULL;
1.1 jruoho 421: }
1.1.1.3 christos 422:
423: /* Check if any errors occurred during compile */
424:
425: Status = AslCheckForErrorExit ();
426: if (ACPI_FAILURE (Status))
427: {
428: return (Status);
429: }
430:
431: /* Cleanup (for next source file) and exit */
432:
1.1 jruoho 433: AeClearErrorLog ();
1.1.1.3 christos 434: PrTerminatePreprocessor ();
1.1 jruoho 435: return (Status);
436:
437: /*
1.1.1.3 christos 438: * ASL Compilation
1.1 jruoho 439: */
440: case ASL_INPUT_TYPE_ASCII_ASL:
441:
1.1.1.14! christos 442: Status = CmDoCompile ();
1.1.1.3 christos 443: if (ACPI_FAILURE (Status))
1.1 jruoho 444: {
1.1.1.3 christos 445: return (Status);
1.1 jruoho 446: }
447:
1.1.1.3 christos 448: /* Cleanup (for next source file) and exit */
449:
1.1 jruoho 450: AeClearErrorLog ();
1.1.1.3 christos 451: PrTerminatePreprocessor ();
1.1.1.9 christos 452:
1.1.1.14! christos 453: /*
! 454: * At this point, we know how many lines are in the input file. Save it
! 455: * to display for post-compilation summary.
! 456: */
! 457: FileNode->TotalLineCount = AslGbl_CurrentLineNumber;
1.1 jruoho 458: return (AE_OK);
459:
1.1.1.3 christos 460: /*
461: * Binary ACPI table was auto-detected, disassemble it
462: */
1.1.1.7 christos 463: case ASL_INPUT_TYPE_BINARY_ACPI_TABLE:
1.1.1.3 christos 464:
465: /* We have what appears to be an ACPI table, disassemble it */
466:
467: FlCloseFile (ASL_FILE_INPUT);
1.1.1.13 christos 468: AslGbl_DoCompile = FALSE;
1.1.1.10 christos 469: AcpiGbl_DisasmFlag = TRUE;
1.1.1.3 christos 470: Status = AslDoDisassembly ();
471: return (Status);
472:
473: /* Unknown binary table */
474:
1.1 jruoho 475: case ASL_INPUT_TYPE_BINARY:
476:
477: AePrintErrorLog (ASL_FILE_STDERR);
478: return (AE_ERROR);
479:
480: default:
1.1.1.3 christos 481:
1.1.1.13 christos 482: printf ("Unknown file type %X\n", AslGbl_FileType);
1.1 jruoho 483: return (AE_ERROR);
484: }
485: }
486:
487:
488: /*******************************************************************************
489: *
1.1.1.3 christos 490: * FUNCTION: AslCheckForErrorExit
1.1 jruoho 491: *
1.1.1.3 christos 492: * PARAMETERS: None. Examines global exception count array
1.1 jruoho 493: *
494: * RETURN: Status
495: *
1.1.1.3 christos 496: * DESCRIPTION: Determine if compiler should abort with error status
1.1 jruoho 497: *
498: ******************************************************************************/
499:
500: ACPI_STATUS
1.1.1.3 christos 501: AslCheckForErrorExit (
502: void)
1.1 jruoho 503: {
504:
1.1.1.3 christos 505: /*
506: * Return non-zero exit code if there have been errors, unless the
507: * global ignore error flag has been set
508: */
1.1.1.13 christos 509: if (!AslGbl_IgnoreErrors)
1.1 jruoho 510: {
1.1.1.13 christos 511: if (AslGbl_ExceptionCount[ASL_ERROR] > 0)
1.1 jruoho 512: {
1.1.1.3 christos 513: return (AE_ERROR);
1.1 jruoho 514: }
515:
1.1.1.3 christos 516: /* Optionally treat warnings as errors */
1.1 jruoho 517:
1.1.1.13 christos 518: if (AslGbl_WarningsAsErrors)
1.1.1.3 christos 519: {
1.1.1.13 christos 520: if ((AslGbl_ExceptionCount[ASL_WARNING] > 0) ||
521: (AslGbl_ExceptionCount[ASL_WARNING2] > 0) ||
522: (AslGbl_ExceptionCount[ASL_WARNING3] > 0))
1.1.1.3 christos 523: {
1.1.1.14! christos 524: AslError (ASL_ERROR, ASL_MSG_WARNING_AS_ERROR, NULL,
! 525: "(reporting warnings as errors)");
1.1.1.3 christos 526: return (AE_ERROR);
527: }
528: }
1.1 jruoho 529: }
530:
1.1.1.3 christos 531: return (AE_OK);
1.1 jruoho 532: }
CVSweb <webmaster@jp.NetBSD.org>