128c506b8Sjruoho /******************************************************************************
228c506b8Sjruoho *
328c506b8Sjruoho * Module Name: asllisting - Listing file generation
428c506b8Sjruoho *
528c506b8Sjruoho *****************************************************************************/
628c506b8Sjruoho
7124f4c82Sjruoho /*
8*046a2985Schristos * Copyright (C) 2000 - 2023, Intel Corp.
928c506b8Sjruoho * All rights reserved.
1028c506b8Sjruoho *
11124f4c82Sjruoho * Redistribution and use in source and binary forms, with or without
12124f4c82Sjruoho * modification, are permitted provided that the following conditions
13124f4c82Sjruoho * are met:
14124f4c82Sjruoho * 1. Redistributions of source code must retain the above copyright
15124f4c82Sjruoho * notice, this list of conditions, and the following disclaimer,
16124f4c82Sjruoho * without modification.
17124f4c82Sjruoho * 2. Redistributions in binary form must reproduce at minimum a disclaimer
18124f4c82Sjruoho * substantially similar to the "NO WARRANTY" disclaimer below
19124f4c82Sjruoho * ("Disclaimer") and any redistribution must be conditioned upon
20124f4c82Sjruoho * including a substantially similar Disclaimer requirement for further
21124f4c82Sjruoho * binary redistribution.
22124f4c82Sjruoho * 3. Neither the names of the above-listed copyright holders nor the names
23124f4c82Sjruoho * of any contributors may be used to endorse or promote products derived
24124f4c82Sjruoho * from this software without specific prior written permission.
2528c506b8Sjruoho *
26124f4c82Sjruoho * Alternatively, this software may be distributed under the terms of the
27124f4c82Sjruoho * GNU General Public License ("GPL") version 2 as published by the Free
28124f4c82Sjruoho * Software Foundation.
2928c506b8Sjruoho *
30124f4c82Sjruoho * NO WARRANTY
31124f4c82Sjruoho * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
32124f4c82Sjruoho * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
3346a330b4Schristos * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
34124f4c82Sjruoho * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
35124f4c82Sjruoho * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
36124f4c82Sjruoho * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
37124f4c82Sjruoho * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
38124f4c82Sjruoho * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
39124f4c82Sjruoho * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
40124f4c82Sjruoho * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
41124f4c82Sjruoho * POSSIBILITY OF SUCH DAMAGES.
42124f4c82Sjruoho */
4328c506b8Sjruoho
4428c506b8Sjruoho #include "aslcompiler.h"
4528c506b8Sjruoho #include "aslcompiler.y.h"
4628c506b8Sjruoho #include "amlcode.h"
4728c506b8Sjruoho #include "acparser.h"
4828c506b8Sjruoho #include "acnamesp.h"
4928c506b8Sjruoho
50ff4a156dSchristos
5128c506b8Sjruoho #define _COMPONENT ACPI_COMPILER
52ff4a156dSchristos ACPI_MODULE_NAME ("asllisting")
53ff4a156dSchristos
5428c506b8Sjruoho
5528c506b8Sjruoho /* Local prototypes */
5628c506b8Sjruoho
5728c506b8Sjruoho static void
58ff4a156dSchristos LsGenerateListing (
59ff4a156dSchristos UINT32 FileId);
6028c506b8Sjruoho
6128c506b8Sjruoho static ACPI_STATUS
6228c506b8Sjruoho LsAmlListingWalk (
6328c506b8Sjruoho ACPI_PARSE_OBJECT *Op,
6428c506b8Sjruoho UINT32 Level,
6528c506b8Sjruoho void *Context);
6628c506b8Sjruoho
67ff4a156dSchristos static ACPI_STATUS
68ff4a156dSchristos LsTreeWriteWalk (
69ff4a156dSchristos ACPI_PARSE_OBJECT *Op,
70ff4a156dSchristos UINT32 Level,
71ff4a156dSchristos void *Context);
7228c506b8Sjruoho
7328c506b8Sjruoho static void
7428c506b8Sjruoho LsWriteNodeToListing (
7528c506b8Sjruoho ACPI_PARSE_OBJECT *Op,
7628c506b8Sjruoho UINT32 FileId);
7728c506b8Sjruoho
7828c506b8Sjruoho static void
79ff4a156dSchristos LsFinishSourceListing (
80ff4a156dSchristos UINT32 FileId);
8128c506b8Sjruoho
8228c506b8Sjruoho
8328c506b8Sjruoho /*******************************************************************************
8428c506b8Sjruoho *
85ff4a156dSchristos * FUNCTION: LsDoListings
8628c506b8Sjruoho *
87ff4a156dSchristos * PARAMETERS: None. Examines the various output file global flags.
8828c506b8Sjruoho *
89ff4a156dSchristos * RETURN: None
9028c506b8Sjruoho *
91ff4a156dSchristos * DESCRIPTION: Generate all requested listing files.
9228c506b8Sjruoho *
9328c506b8Sjruoho ******************************************************************************/
9428c506b8Sjruoho
9528c506b8Sjruoho void
LsDoListings(void)96ff4a156dSchristos LsDoListings (
9728c506b8Sjruoho void)
9828c506b8Sjruoho {
9928c506b8Sjruoho
1004c4e8184Schristos if (AslGbl_C_OutputFlag)
10128c506b8Sjruoho {
102ff4a156dSchristos LsGenerateListing (ASL_FILE_C_SOURCE_OUTPUT);
103ff4a156dSchristos }
104ff4a156dSchristos
1054c4e8184Schristos if (AslGbl_ListingFlag)
106ff4a156dSchristos {
107ff4a156dSchristos LsGenerateListing (ASL_FILE_LISTING_OUTPUT);
108ff4a156dSchristos }
109ff4a156dSchristos
1104c4e8184Schristos if (AslGbl_AsmOutputFlag)
111ff4a156dSchristos {
112ff4a156dSchristos LsGenerateListing (ASL_FILE_ASM_SOURCE_OUTPUT);
113ff4a156dSchristos }
114ff4a156dSchristos
1154c4e8184Schristos if (AslGbl_C_IncludeOutputFlag)
116ff4a156dSchristos {
117ff4a156dSchristos LsGenerateListing (ASL_FILE_C_INCLUDE_OUTPUT);
118ff4a156dSchristos }
119ff4a156dSchristos
1204c4e8184Schristos if (AslGbl_AsmIncludeOutputFlag)
121ff4a156dSchristos {
122ff4a156dSchristos LsGenerateListing (ASL_FILE_ASM_INCLUDE_OUTPUT);
123ff4a156dSchristos }
124ff4a156dSchristos
1254c4e8184Schristos if (AslGbl_C_OffsetTableFlag)
126ff4a156dSchristos {
127ff4a156dSchristos LsGenerateListing (ASL_FILE_C_OFFSET_OUTPUT);
128ff4a156dSchristos }
129ff4a156dSchristos }
130ff4a156dSchristos
131ff4a156dSchristos
132ff4a156dSchristos /*******************************************************************************
133ff4a156dSchristos *
134ff4a156dSchristos * FUNCTION: LsGenerateListing
135ff4a156dSchristos *
136ff4a156dSchristos * PARAMETERS: FileId - ID of listing file
137ff4a156dSchristos *
138ff4a156dSchristos * RETURN: None
139ff4a156dSchristos *
140ff4a156dSchristos * DESCRIPTION: Generate a listing file. This can be one of the several types
141ff4a156dSchristos * of "listings" supported.
142ff4a156dSchristos *
143ff4a156dSchristos ******************************************************************************/
144ff4a156dSchristos
145ff4a156dSchristos static void
LsGenerateListing(UINT32 FileId)146ff4a156dSchristos LsGenerateListing (
147ff4a156dSchristos UINT32 FileId)
148ff4a156dSchristos {
14994783addSchristos UINT32 WalkMode = ASL_WALK_VISIT_DOWNWARD | ASL_WALK_VISIT_DB_SEPARATELY;
150ff4a156dSchristos
151ff4a156dSchristos /* Start at the beginning of both the source and AML files */
152ff4a156dSchristos
153ff4a156dSchristos FlSeekFile (ASL_FILE_SOURCE_OUTPUT, 0);
154ff4a156dSchristos FlSeekFile (ASL_FILE_AML_OUTPUT, 0);
1554c4e8184Schristos AslGbl_SourceLine = 0;
1564c4e8184Schristos AslGbl_CurrentHexColumn = 0;
1574c4e8184Schristos LsPushNode (AslGbl_Files[ASL_FILE_INPUT].Filename);
158ff4a156dSchristos
159ff4a156dSchristos if (FileId == ASL_FILE_C_OFFSET_OUTPUT)
160ff4a156dSchristos {
1614c4e8184Schristos AslGbl_CurrentAmlOffset = 0;
162ff4a156dSchristos
163ff4a156dSchristos /* Offset table file has a special header and footer */
164ff4a156dSchristos
165ff4a156dSchristos LsDoOffsetTableHeader (FileId);
166ff4a156dSchristos
16794783addSchristos TrWalkParseTree (AslGbl_CurrentDB, WalkMode,
168cfbb7280Schristos LsAmlOffsetWalk, NULL, (void *) ACPI_TO_POINTER (FileId));
169ff4a156dSchristos LsDoOffsetTableFooter (FileId);
17028c506b8Sjruoho return;
17128c506b8Sjruoho }
17228c506b8Sjruoho
173ff4a156dSchristos /* Process all parse nodes */
17428c506b8Sjruoho
17594783addSchristos TrWalkParseTree (AslGbl_CurrentDB, WalkMode,
176cfbb7280Schristos LsAmlListingWalk, NULL, (void *) ACPI_TO_POINTER (FileId));
17728c506b8Sjruoho
178ff4a156dSchristos /* Final processing */
17928c506b8Sjruoho
180ff4a156dSchristos LsFinishSourceListing (FileId);
18128c506b8Sjruoho }
18228c506b8Sjruoho
18328c506b8Sjruoho
18428c506b8Sjruoho /*******************************************************************************
18528c506b8Sjruoho *
18628c506b8Sjruoho * FUNCTION: LsAmlListingWalk
18728c506b8Sjruoho *
18828c506b8Sjruoho * PARAMETERS: ASL_WALK_CALLBACK
18928c506b8Sjruoho *
19028c506b8Sjruoho * RETURN: Status
19128c506b8Sjruoho *
19228c506b8Sjruoho * DESCRIPTION: Process one node during a listing file generation.
19328c506b8Sjruoho *
19428c506b8Sjruoho ******************************************************************************/
19528c506b8Sjruoho
19628c506b8Sjruoho static ACPI_STATUS
LsAmlListingWalk(ACPI_PARSE_OBJECT * Op,UINT32 Level,void * Context)19728c506b8Sjruoho LsAmlListingWalk (
19828c506b8Sjruoho ACPI_PARSE_OBJECT *Op,
19928c506b8Sjruoho UINT32 Level,
20028c506b8Sjruoho void *Context)
20128c506b8Sjruoho {
20228c506b8Sjruoho UINT8 FileByte;
20328c506b8Sjruoho UINT32 i;
20428c506b8Sjruoho UINT32 FileId = (UINT32) ACPI_TO_INTEGER (Context);
20528c506b8Sjruoho
20628c506b8Sjruoho
20728c506b8Sjruoho LsWriteNodeToListing (Op, FileId);
20828c506b8Sjruoho
20989b8eb6cSchristos if (Op->Asl.CompileFlags & OP_IS_RESOURCE_DATA)
21028c506b8Sjruoho {
21128c506b8Sjruoho /* Buffer is a resource template, don't dump the data all at once */
21228c506b8Sjruoho
21328c506b8Sjruoho return (AE_OK);
21428c506b8Sjruoho }
21528c506b8Sjruoho
21671e38f1dSchristos if ((FileId == ASL_FILE_ASM_INCLUDE_OUTPUT) ||
21771e38f1dSchristos (FileId == ASL_FILE_C_INCLUDE_OUTPUT))
21871e38f1dSchristos {
21971e38f1dSchristos return (AE_OK);
22071e38f1dSchristos }
22171e38f1dSchristos
22228c506b8Sjruoho /* Write the hex bytes to the listing file(s) (if requested) */
22328c506b8Sjruoho
22428c506b8Sjruoho for (i = 0; i < Op->Asl.FinalAmlLength; i++)
22528c506b8Sjruoho {
22628c506b8Sjruoho if (ACPI_FAILURE (FlReadFile (ASL_FILE_AML_OUTPUT, &FileByte, 1)))
22728c506b8Sjruoho {
22828c506b8Sjruoho FlFileError (ASL_FILE_AML_OUTPUT, ASL_MSG_READ);
22928c506b8Sjruoho AslAbort ();
23028c506b8Sjruoho }
23171e38f1dSchristos
23228c506b8Sjruoho LsWriteListingHexBytes (&FileByte, 1, FileId);
23328c506b8Sjruoho }
23428c506b8Sjruoho
23528c506b8Sjruoho return (AE_OK);
23628c506b8Sjruoho }
23728c506b8Sjruoho
23828c506b8Sjruoho
23928c506b8Sjruoho /*******************************************************************************
24028c506b8Sjruoho *
241ff4a156dSchristos * FUNCTION: LsDumpParseTree, LsTreeWriteWalk
24228c506b8Sjruoho *
243ff4a156dSchristos * PARAMETERS: None
24428c506b8Sjruoho *
24528c506b8Sjruoho * RETURN: None
24628c506b8Sjruoho *
247ff4a156dSchristos * DESCRIPTION: Dump entire parse tree, for compiler debug only
24828c506b8Sjruoho *
24928c506b8Sjruoho ******************************************************************************/
25028c506b8Sjruoho
25128c506b8Sjruoho void
LsDumpParseTree(void)252ff4a156dSchristos LsDumpParseTree (
25328c506b8Sjruoho void)
25428c506b8Sjruoho {
25528c506b8Sjruoho
2564c4e8184Schristos if (!AslGbl_DebugFlag)
25728c506b8Sjruoho {
25828c506b8Sjruoho return;
25928c506b8Sjruoho }
26028c506b8Sjruoho
261ff4a156dSchristos DbgPrint (ASL_TREE_OUTPUT, "\nOriginal parse tree from parser:\n\n");
262cfbb7280Schristos DbgPrint (ASL_TREE_OUTPUT, ASL_PARSE_TREE_HEADER1);
263cfbb7280Schristos
2644c4e8184Schristos TrWalkParseTree (AslGbl_ParseTreeRoot, ASL_WALK_VISIT_DOWNWARD,
265ff4a156dSchristos LsTreeWriteWalk, NULL, NULL);
266cfbb7280Schristos
267cfbb7280Schristos DbgPrint (ASL_TREE_OUTPUT, ASL_PARSE_TREE_HEADER1);
26828c506b8Sjruoho }
26928c506b8Sjruoho
27028c506b8Sjruoho
271ff4a156dSchristos static ACPI_STATUS
LsTreeWriteWalk(ACPI_PARSE_OBJECT * Op,UINT32 Level,void * Context)272ff4a156dSchristos LsTreeWriteWalk (
273ff4a156dSchristos ACPI_PARSE_OBJECT *Op,
274ff4a156dSchristos UINT32 Level,
275ff4a156dSchristos void *Context)
27628c506b8Sjruoho {
27728c506b8Sjruoho
278cfbb7280Schristos /* Dump ParseOp name and possible value */
27928c506b8Sjruoho
280cfbb7280Schristos switch (Op->Asl.ParseOpcode)
281cfbb7280Schristos {
282cfbb7280Schristos case PARSEOP_NAMESEG:
283cfbb7280Schristos case PARSEOP_NAMESTRING:
284cfbb7280Schristos case PARSEOP_METHODCALL:
285cfbb7280Schristos case PARSEOP_STRING_LITERAL:
28628c506b8Sjruoho
287cfbb7280Schristos UtDumpStringOp (Op, Level);
288cfbb7280Schristos break;
28928c506b8Sjruoho
290cfbb7280Schristos case PARSEOP_BYTECONST:
291cfbb7280Schristos
292cfbb7280Schristos UtDumpIntegerOp (Op, Level, 2);
293cfbb7280Schristos break;
294cfbb7280Schristos
295cfbb7280Schristos case PARSEOP_WORDCONST:
296cfbb7280Schristos case PARSEOP_PACKAGE_LENGTH:
297cfbb7280Schristos
298cfbb7280Schristos UtDumpIntegerOp (Op, Level, 4);
299cfbb7280Schristos break;
300cfbb7280Schristos
301cfbb7280Schristos case PARSEOP_DWORDCONST:
302cfbb7280Schristos case PARSEOP_EISAID:
303cfbb7280Schristos
304cfbb7280Schristos UtDumpIntegerOp (Op, Level, 8);
305cfbb7280Schristos break;
306cfbb7280Schristos
307cfbb7280Schristos case PARSEOP_QWORDCONST:
308cfbb7280Schristos case PARSEOP_INTEGER:
309cfbb7280Schristos case PARSEOP_ONE:
310cfbb7280Schristos case PARSEOP_ZERO:
311cfbb7280Schristos case PARSEOP_ONES:
312cfbb7280Schristos
313cfbb7280Schristos UtDumpIntegerOp (Op, Level, 16);
314cfbb7280Schristos break;
315cfbb7280Schristos
316cfbb7280Schristos case PARSEOP_INCLUDE:
317cfbb7280Schristos
31871e38f1dSchristos DbgPrint (ASL_TREE_OUTPUT,
31971e38f1dSchristos "Open: %s\n", Op->Asl.Value.String);
32071e38f1dSchristos return (AE_OK);
321cfbb7280Schristos
322cfbb7280Schristos case PARSEOP_INCLUDE_END:
323cfbb7280Schristos
32471e38f1dSchristos DbgPrint (ASL_TREE_OUTPUT,
32571e38f1dSchristos "Close: %s\n", Op->Asl.Filename);
32671e38f1dSchristos return (AE_OK);
327cfbb7280Schristos
328cfbb7280Schristos default:
329cfbb7280Schristos
330cfbb7280Schristos UtDumpBasicOp (Op, Level);
331cfbb7280Schristos break;
33271e38f1dSchristos }
33371e38f1dSchristos
334cfbb7280Schristos /* Dump the remaining data */
335cfbb7280Schristos
336cfbb7280Schristos DbgPrint (ASL_TREE_OUTPUT, ASL_PARSE_TREE_DEBUG1,
337cfbb7280Schristos Op->Asl.ParseOpcode, Op->Asl.CompileFlags,
338cfbb7280Schristos Op->Asl.LineNumber, Op->Asl.EndLine,
339cfbb7280Schristos Op->Asl.LogicalLineNumber, Op->Asl.EndLogicalLine);
340cfbb7280Schristos
34189b8eb6cSchristos TrPrintOpFlags (Op->Asl.CompileFlags, ASL_TREE_OUTPUT);
342679c17fdSchristos DbgPrint (ASL_TREE_OUTPUT, "\n");
343ff4a156dSchristos return (AE_OK);
34428c506b8Sjruoho }
34528c506b8Sjruoho
34628c506b8Sjruoho
34728c506b8Sjruoho /*******************************************************************************
34828c506b8Sjruoho *
34928c506b8Sjruoho * FUNCTION: LsWriteNodeToListing
35028c506b8Sjruoho *
35128c506b8Sjruoho * PARAMETERS: Op - Parse node to write to the listing file.
35228c506b8Sjruoho * FileId - ID of current listing file
35328c506b8Sjruoho *
35428c506b8Sjruoho * RETURN: None.
35528c506b8Sjruoho *
35628c506b8Sjruoho * DESCRIPTION: Write "a node" to the listing file. This means to
35728c506b8Sjruoho * 1) Write out all of the source text associated with the node
35828c506b8Sjruoho * 2) Write out all of the AML bytes associated with the node
35928c506b8Sjruoho * 3) Write any compiler exceptions associated with the node
36028c506b8Sjruoho *
36128c506b8Sjruoho ******************************************************************************/
36228c506b8Sjruoho
36328c506b8Sjruoho static void
LsWriteNodeToListing(ACPI_PARSE_OBJECT * Op,UINT32 FileId)36428c506b8Sjruoho LsWriteNodeToListing (
36528c506b8Sjruoho ACPI_PARSE_OBJECT *Op,
36628c506b8Sjruoho UINT32 FileId)
36728c506b8Sjruoho {
36828c506b8Sjruoho const ACPI_OPCODE_INFO *OpInfo;
36928c506b8Sjruoho UINT32 OpClass;
37028c506b8Sjruoho char *Pathname;
37128c506b8Sjruoho UINT32 Length;
37228c506b8Sjruoho UINT32 i;
37328c506b8Sjruoho
37428c506b8Sjruoho
37528c506b8Sjruoho OpInfo = AcpiPsGetOpcodeInfo (Op->Asl.AmlOpcode);
37628c506b8Sjruoho OpClass = OpInfo->Class;
37728c506b8Sjruoho
37828c506b8Sjruoho /* TBD: clean this up with a single flag that says:
37928c506b8Sjruoho * I start a named output block
38028c506b8Sjruoho */
38128c506b8Sjruoho if (FileId == ASL_FILE_C_SOURCE_OUTPUT)
38228c506b8Sjruoho {
38328c506b8Sjruoho switch (Op->Asl.ParseOpcode)
38428c506b8Sjruoho {
38571e38f1dSchristos case PARSEOP_DEFINITION_BLOCK:
38628c506b8Sjruoho case PARSEOP_METHODCALL:
38728c506b8Sjruoho case PARSEOP_INCLUDE:
38828c506b8Sjruoho case PARSEOP_INCLUDE_END:
38928c506b8Sjruoho case PARSEOP_DEFAULT_ARG:
39028c506b8Sjruoho
39128c506b8Sjruoho break;
39228c506b8Sjruoho
39328c506b8Sjruoho default:
394ff4a156dSchristos
39528c506b8Sjruoho switch (OpClass)
39628c506b8Sjruoho {
39728c506b8Sjruoho case AML_CLASS_NAMED_OBJECT:
398ff4a156dSchristos
39928c506b8Sjruoho switch (Op->Asl.AmlOpcode)
40028c506b8Sjruoho {
40128c506b8Sjruoho case AML_SCOPE_OP:
40228c506b8Sjruoho case AML_ALIAS_OP:
403ff4a156dSchristos
40428c506b8Sjruoho break;
40528c506b8Sjruoho
40628c506b8Sjruoho default:
407ff4a156dSchristos
40828c506b8Sjruoho if (Op->Asl.ExternalName)
40928c506b8Sjruoho {
41028c506b8Sjruoho LsFlushListingBuffer (FileId);
41128c506b8Sjruoho FlPrintFile (FileId, " };\n");
41228c506b8Sjruoho }
41328c506b8Sjruoho break;
41428c506b8Sjruoho }
41528c506b8Sjruoho break;
41628c506b8Sjruoho
41728c506b8Sjruoho default:
418ff4a156dSchristos
41928c506b8Sjruoho /* Don't care about other objects */
420ff4a156dSchristos
42128c506b8Sjruoho break;
42228c506b8Sjruoho }
42328c506b8Sjruoho break;
42428c506b8Sjruoho }
42528c506b8Sjruoho }
42628c506b8Sjruoho
42728c506b8Sjruoho /* These cases do not have a corresponding AML opcode */
42828c506b8Sjruoho
42928c506b8Sjruoho switch (Op->Asl.ParseOpcode)
43028c506b8Sjruoho {
43171e38f1dSchristos case PARSEOP_DEFINITION_BLOCK:
43228c506b8Sjruoho
433cfbb7280Schristos /* Always start a definition block at AML offset zero */
434cfbb7280Schristos
4354c4e8184Schristos AslGbl_CurrentAmlOffset = 0;
43628c506b8Sjruoho LsWriteSourceLines (Op->Asl.EndLine, Op->Asl.EndLogicalLine, FileId);
43728c506b8Sjruoho
43828c506b8Sjruoho /* Use the table Signature and TableId to build a unique name */
43928c506b8Sjruoho
44071e38f1dSchristos switch (FileId)
44128c506b8Sjruoho {
44271e38f1dSchristos case ASL_FILE_ASM_SOURCE_OUTPUT:
44371e38f1dSchristos
44428c506b8Sjruoho FlPrintFile (FileId,
44528c506b8Sjruoho "%s_%s_Header \\\n",
4464c4e8184Schristos AslGbl_TableSignature, AslGbl_TableId);
44771e38f1dSchristos break;
44871e38f1dSchristos
44971e38f1dSchristos case ASL_FILE_C_SOURCE_OUTPUT:
45071e38f1dSchristos
45128c506b8Sjruoho FlPrintFile (FileId,
45228c506b8Sjruoho " unsigned char %s_%s_Header [] =\n {\n",
4534c4e8184Schristos AslGbl_TableSignature, AslGbl_TableId);
45471e38f1dSchristos break;
45571e38f1dSchristos
45671e38f1dSchristos case ASL_FILE_ASM_INCLUDE_OUTPUT:
45771e38f1dSchristos
45828c506b8Sjruoho FlPrintFile (FileId,
45928c506b8Sjruoho "extrn %s_%s_Header : byte\n",
4604c4e8184Schristos AslGbl_TableSignature, AslGbl_TableId);
46171e38f1dSchristos break;
46271e38f1dSchristos
46371e38f1dSchristos case ASL_FILE_C_INCLUDE_OUTPUT:
46471e38f1dSchristos
46528c506b8Sjruoho FlPrintFile (FileId,
46628c506b8Sjruoho "extern unsigned char %s_%s_Header [];\n",
4674c4e8184Schristos AslGbl_TableSignature, AslGbl_TableId);
46871e38f1dSchristos break;
46971e38f1dSchristos
47071e38f1dSchristos default:
47171e38f1dSchristos break;
47228c506b8Sjruoho }
47371e38f1dSchristos
47428c506b8Sjruoho return;
47528c506b8Sjruoho
47628c506b8Sjruoho
47728c506b8Sjruoho case PARSEOP_METHODCALL:
47828c506b8Sjruoho
47928c506b8Sjruoho LsWriteSourceLines (Op->Asl.LineNumber, Op->Asl.LogicalLineNumber,
48028c506b8Sjruoho FileId);
48128c506b8Sjruoho return;
48228c506b8Sjruoho
48328c506b8Sjruoho
48428c506b8Sjruoho case PARSEOP_INCLUDE:
48528c506b8Sjruoho
48628c506b8Sjruoho /* Flush everything up to and including the include source line */
48728c506b8Sjruoho
48828c506b8Sjruoho LsWriteSourceLines (Op->Asl.LineNumber, Op->Asl.LogicalLineNumber,
48928c506b8Sjruoho FileId);
49028c506b8Sjruoho
49128c506b8Sjruoho /* Create a new listing node and push it */
49228c506b8Sjruoho
49371e38f1dSchristos LsPushNode (Op->Asl.Value.String);
49428c506b8Sjruoho return;
49528c506b8Sjruoho
49628c506b8Sjruoho
49728c506b8Sjruoho case PARSEOP_INCLUDE_END:
49828c506b8Sjruoho
49928c506b8Sjruoho /* Flush out the rest of the include file */
50028c506b8Sjruoho
50128c506b8Sjruoho LsWriteSourceLines (Op->Asl.LineNumber, Op->Asl.LogicalLineNumber,
50228c506b8Sjruoho FileId);
50328c506b8Sjruoho
50428c506b8Sjruoho /* Pop off this listing node and go back to the parent file */
50528c506b8Sjruoho
50628c506b8Sjruoho (void) LsPopNode ();
50728c506b8Sjruoho return;
50828c506b8Sjruoho
50928c506b8Sjruoho
51028c506b8Sjruoho case PARSEOP_DEFAULT_ARG:
51128c506b8Sjruoho
51289b8eb6cSchristos if (Op->Asl.CompileFlags & OP_IS_RESOURCE_DESC)
51328c506b8Sjruoho {
51428c506b8Sjruoho LsWriteSourceLines (Op->Asl.LineNumber, Op->Asl.EndLogicalLine,
51528c506b8Sjruoho FileId);
51628c506b8Sjruoho }
51728c506b8Sjruoho return;
51828c506b8Sjruoho
51928c506b8Sjruoho
52028c506b8Sjruoho default:
521ff4a156dSchristos
52228c506b8Sjruoho /* All other opcodes have an AML opcode */
523ff4a156dSchristos
52428c506b8Sjruoho break;
52528c506b8Sjruoho }
52628c506b8Sjruoho
52728c506b8Sjruoho /*
52828c506b8Sjruoho * Otherwise, we look at the AML opcode because we can
52928c506b8Sjruoho * switch on the opcode type, getting an entire class
53028c506b8Sjruoho * at once
53128c506b8Sjruoho */
53228c506b8Sjruoho switch (OpClass)
53328c506b8Sjruoho {
53428c506b8Sjruoho case AML_CLASS_ARGUMENT: /* argument type only */
53528c506b8Sjruoho case AML_CLASS_INTERNAL:
53628c506b8Sjruoho
53728c506b8Sjruoho break;
53828c506b8Sjruoho
53928c506b8Sjruoho case AML_CLASS_NAMED_OBJECT:
54028c506b8Sjruoho
54128c506b8Sjruoho switch (Op->Asl.AmlOpcode)
54228c506b8Sjruoho {
54328c506b8Sjruoho case AML_FIELD_OP:
54428c506b8Sjruoho case AML_INDEX_FIELD_OP:
54528c506b8Sjruoho case AML_BANK_FIELD_OP:
54628c506b8Sjruoho /*
54728c506b8Sjruoho * For fields, we want to dump all the AML after the
54828c506b8Sjruoho * entire definition
54928c506b8Sjruoho */
55028c506b8Sjruoho LsWriteSourceLines (Op->Asl.EndLine, Op->Asl.EndLogicalLine,
55128c506b8Sjruoho FileId);
55228c506b8Sjruoho break;
55328c506b8Sjruoho
55428c506b8Sjruoho case AML_NAME_OP:
55528c506b8Sjruoho
55689b8eb6cSchristos if (Op->Asl.CompileFlags & OP_IS_RESOURCE_DESC)
55728c506b8Sjruoho {
55828c506b8Sjruoho LsWriteSourceLines (Op->Asl.LineNumber, Op->Asl.LogicalLineNumber,
55928c506b8Sjruoho FileId);
56028c506b8Sjruoho }
56128c506b8Sjruoho else
56228c506b8Sjruoho {
56328c506b8Sjruoho /*
56428c506b8Sjruoho * For fields, we want to dump all the AML after the
56528c506b8Sjruoho * entire definition
56628c506b8Sjruoho */
56728c506b8Sjruoho LsWriteSourceLines (Op->Asl.EndLine, Op->Asl.EndLogicalLine,
56828c506b8Sjruoho FileId);
56928c506b8Sjruoho }
57028c506b8Sjruoho break;
57128c506b8Sjruoho
57228c506b8Sjruoho default:
573ff4a156dSchristos
57428c506b8Sjruoho LsWriteSourceLines (Op->Asl.LineNumber, Op->Asl.LogicalLineNumber,
57528c506b8Sjruoho FileId);
57628c506b8Sjruoho break;
57728c506b8Sjruoho }
57828c506b8Sjruoho
57928c506b8Sjruoho switch (Op->Asl.AmlOpcode)
58028c506b8Sjruoho {
58128c506b8Sjruoho case AML_SCOPE_OP:
58228c506b8Sjruoho case AML_ALIAS_OP:
58328c506b8Sjruoho
58428c506b8Sjruoho /* These opcodes do not declare a new object, ignore them */
58528c506b8Sjruoho
58628c506b8Sjruoho break;
58728c506b8Sjruoho
58828c506b8Sjruoho default:
58928c506b8Sjruoho
59028c506b8Sjruoho /* All other named object opcodes come here */
59128c506b8Sjruoho
59228c506b8Sjruoho switch (FileId)
59328c506b8Sjruoho {
59428c506b8Sjruoho case ASL_FILE_ASM_SOURCE_OUTPUT:
59528c506b8Sjruoho case ASL_FILE_C_SOURCE_OUTPUT:
59628c506b8Sjruoho case ASL_FILE_ASM_INCLUDE_OUTPUT:
59728c506b8Sjruoho case ASL_FILE_C_INCLUDE_OUTPUT:
59828c506b8Sjruoho /*
59928c506b8Sjruoho * For named objects, we will create a valid symbol so that the
60028c506b8Sjruoho * AML code can be referenced from C or ASM
60128c506b8Sjruoho */
60228c506b8Sjruoho if (Op->Asl.ExternalName)
60328c506b8Sjruoho {
60428c506b8Sjruoho /* Get the full pathname associated with this node */
60528c506b8Sjruoho
60628c506b8Sjruoho Pathname = AcpiNsGetExternalPathname (Op->Asl.Node);
60728c506b8Sjruoho Length = strlen (Pathname);
60828c506b8Sjruoho if (Length >= 4)
60928c506b8Sjruoho {
61028c506b8Sjruoho /* Convert all dots in the path to underscores */
61128c506b8Sjruoho
61228c506b8Sjruoho for (i = 0; i < Length; i++)
61328c506b8Sjruoho {
61428c506b8Sjruoho if (Pathname[i] == '.')
61528c506b8Sjruoho {
61628c506b8Sjruoho Pathname[i] = '_';
61728c506b8Sjruoho }
61828c506b8Sjruoho }
61928c506b8Sjruoho
62028c506b8Sjruoho /* Create the appropriate symbol in the output file */
62128c506b8Sjruoho
62271e38f1dSchristos switch (FileId)
62328c506b8Sjruoho {
62471e38f1dSchristos case ASL_FILE_ASM_SOURCE_OUTPUT:
62571e38f1dSchristos
62628c506b8Sjruoho FlPrintFile (FileId,
62728c506b8Sjruoho "%s_%s_%s \\\n",
6284c4e8184Schristos AslGbl_TableSignature, AslGbl_TableId, &Pathname[1]);
62971e38f1dSchristos break;
63071e38f1dSchristos
63171e38f1dSchristos case ASL_FILE_C_SOURCE_OUTPUT:
63271e38f1dSchristos
63328c506b8Sjruoho FlPrintFile (FileId,
63428c506b8Sjruoho " unsigned char %s_%s_%s [] =\n {\n",
6354c4e8184Schristos AslGbl_TableSignature, AslGbl_TableId, &Pathname[1]);
63671e38f1dSchristos break;
63771e38f1dSchristos
63871e38f1dSchristos case ASL_FILE_ASM_INCLUDE_OUTPUT:
63971e38f1dSchristos
64028c506b8Sjruoho FlPrintFile (FileId,
64128c506b8Sjruoho "extrn %s_%s_%s : byte\n",
6424c4e8184Schristos AslGbl_TableSignature, AslGbl_TableId, &Pathname[1]);
64371e38f1dSchristos break;
64471e38f1dSchristos
64571e38f1dSchristos case ASL_FILE_C_INCLUDE_OUTPUT:
64671e38f1dSchristos
64728c506b8Sjruoho FlPrintFile (FileId,
64828c506b8Sjruoho "extern unsigned char %s_%s_%s [];\n",
6494c4e8184Schristos AslGbl_TableSignature, AslGbl_TableId, &Pathname[1]);
65071e38f1dSchristos break;
65171e38f1dSchristos
65271e38f1dSchristos default:
65371e38f1dSchristos break;
65428c506b8Sjruoho }
65528c506b8Sjruoho }
65671e38f1dSchristos
65728c506b8Sjruoho ACPI_FREE (Pathname);
65828c506b8Sjruoho }
65928c506b8Sjruoho break;
66028c506b8Sjruoho
66128c506b8Sjruoho default:
662ff4a156dSchristos
66328c506b8Sjruoho /* Nothing to do for listing file */
664ff4a156dSchristos
66528c506b8Sjruoho break;
66628c506b8Sjruoho }
66728c506b8Sjruoho }
66828c506b8Sjruoho break;
66928c506b8Sjruoho
67028c506b8Sjruoho case AML_CLASS_EXECUTE:
67128c506b8Sjruoho case AML_CLASS_CREATE:
67228c506b8Sjruoho default:
67328c506b8Sjruoho
67428c506b8Sjruoho if ((Op->Asl.ParseOpcode == PARSEOP_BUFFER) &&
67589b8eb6cSchristos (Op->Asl.CompileFlags & OP_IS_RESOURCE_DESC))
67628c506b8Sjruoho {
67728c506b8Sjruoho return;
67828c506b8Sjruoho }
67928c506b8Sjruoho
68028c506b8Sjruoho LsWriteSourceLines (Op->Asl.LineNumber, Op->Asl.LogicalLineNumber,
68128c506b8Sjruoho FileId);
68228c506b8Sjruoho break;
68328c506b8Sjruoho
68428c506b8Sjruoho case AML_CLASS_UNKNOWN:
685ff4a156dSchristos
68628c506b8Sjruoho break;
68728c506b8Sjruoho }
68828c506b8Sjruoho }
68928c506b8Sjruoho
69028c506b8Sjruoho
69128c506b8Sjruoho /*******************************************************************************
69228c506b8Sjruoho *
693ff4a156dSchristos * FUNCTION: LsFinishSourceListing
69428c506b8Sjruoho *
695ff4a156dSchristos * PARAMETERS: FileId - ID of current listing file.
69628c506b8Sjruoho *
697ff4a156dSchristos * RETURN: None
69828c506b8Sjruoho *
699ff4a156dSchristos * DESCRIPTION: Cleanup routine for the listing file. Flush the hex AML
700ff4a156dSchristos * listing buffer, and flush out any remaining lines in the
701ff4a156dSchristos * source input file.
70228c506b8Sjruoho *
70328c506b8Sjruoho ******************************************************************************/
70428c506b8Sjruoho
70528c506b8Sjruoho static void
LsFinishSourceListing(UINT32 FileId)706ff4a156dSchristos LsFinishSourceListing (
707ff4a156dSchristos UINT32 FileId)
70828c506b8Sjruoho {
70928c506b8Sjruoho
710ff4a156dSchristos if ((FileId == ASL_FILE_ASM_INCLUDE_OUTPUT) ||
711ff4a156dSchristos (FileId == ASL_FILE_C_INCLUDE_OUTPUT))
71228c506b8Sjruoho {
713ff4a156dSchristos return;
71428c506b8Sjruoho }
71528c506b8Sjruoho
716ff4a156dSchristos LsFlushListingBuffer (FileId);
7174c4e8184Schristos AslGbl_CurrentAmlOffset = 0;
71828c506b8Sjruoho
719ff4a156dSchristos /* Flush any remaining text in the source file */
720ff4a156dSchristos
721ff4a156dSchristos if (FileId == ASL_FILE_C_SOURCE_OUTPUT)
72228c506b8Sjruoho {
723ff4a156dSchristos FlPrintFile (FileId, " /*\n");
724ff4a156dSchristos }
725ff4a156dSchristos
726ff4a156dSchristos while (LsWriteOneSourceLine (FileId))
727ff4a156dSchristos { ; }
728ff4a156dSchristos
729ff4a156dSchristos if (FileId == ASL_FILE_C_SOURCE_OUTPUT)
73028c506b8Sjruoho {
731ff4a156dSchristos FlPrintFile (FileId, "\n */\n };\n");
73228c506b8Sjruoho }
733ff4a156dSchristos
734ff4a156dSchristos FlPrintFile (FileId, "\n");
735ff4a156dSchristos
736ff4a156dSchristos if (FileId == ASL_FILE_LISTING_OUTPUT)
73728c506b8Sjruoho {
738ff4a156dSchristos /* Print a summary of the compile exceptions */
739ff4a156dSchristos
740ff4a156dSchristos FlPrintFile (FileId, "\n\nSummary of errors and warnings\n\n");
741ff4a156dSchristos AePrintErrorLog (FileId);
742ff4a156dSchristos FlPrintFile (FileId, "\n");
74394783addSchristos UtDisplayOneSummary (FileId, TRUE);
744ff4a156dSchristos FlPrintFile (FileId, "\n");
74528c506b8Sjruoho }
74628c506b8Sjruoho }
747