128c506b8Sjruoho /******************************************************************************
228c506b8Sjruoho *
328c506b8Sjruoho * Module Name: aslutils -- compiler utilities
428c506b8Sjruoho *
528c506b8Sjruoho *****************************************************************************/
628c506b8Sjruoho
7159c4e26Sjruoho /*
8*2c7d7e3cSchristos * Copyright (C) 2000 - 2023, Intel Corp.
928c506b8Sjruoho * All rights reserved.
1028c506b8Sjruoho *
11159c4e26Sjruoho * Redistribution and use in source and binary forms, with or without
12159c4e26Sjruoho * modification, are permitted provided that the following conditions
13159c4e26Sjruoho * are met:
14159c4e26Sjruoho * 1. Redistributions of source code must retain the above copyright
15159c4e26Sjruoho * notice, this list of conditions, and the following disclaimer,
16159c4e26Sjruoho * without modification.
17159c4e26Sjruoho * 2. Redistributions in binary form must reproduce at minimum a disclaimer
18159c4e26Sjruoho * substantially similar to the "NO WARRANTY" disclaimer below
19159c4e26Sjruoho * ("Disclaimer") and any redistribution must be conditioned upon
20159c4e26Sjruoho * including a substantially similar Disclaimer requirement for further
21159c4e26Sjruoho * binary redistribution.
22159c4e26Sjruoho * 3. Neither the names of the above-listed copyright holders nor the names
23159c4e26Sjruoho * of any contributors may be used to endorse or promote products derived
24159c4e26Sjruoho * from this software without specific prior written permission.
2528c506b8Sjruoho *
26159c4e26Sjruoho * Alternatively, this software may be distributed under the terms of the
27159c4e26Sjruoho * GNU General Public License ("GPL") version 2 as published by the Free
28159c4e26Sjruoho * Software Foundation.
2928c506b8Sjruoho *
30159c4e26Sjruoho * NO WARRANTY
31159c4e26Sjruoho * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
32159c4e26Sjruoho * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
3398244dcfSchristos * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
34159c4e26Sjruoho * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
35159c4e26Sjruoho * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
36159c4e26Sjruoho * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
37159c4e26Sjruoho * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
38159c4e26Sjruoho * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
39159c4e26Sjruoho * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
40159c4e26Sjruoho * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
41159c4e26Sjruoho * POSSIBILITY OF SUCH DAMAGES.
42159c4e26Sjruoho */
4328c506b8Sjruoho
4428c506b8Sjruoho #include "aslcompiler.h"
4528c506b8Sjruoho #include "aslcompiler.y.h"
46159c4e26Sjruoho #include "acdisasm.h"
4728c506b8Sjruoho #include "acnamesp.h"
4828c506b8Sjruoho #include "amlcode.h"
4981bd9c9cSchristos #include "acapps.h"
5081bd9c9cSchristos #include <sys/stat.h>
5181bd9c9cSchristos
5228c506b8Sjruoho
5328c506b8Sjruoho #define _COMPONENT ACPI_COMPILER
5428c506b8Sjruoho ACPI_MODULE_NAME ("aslutils")
5528c506b8Sjruoho
5628c506b8Sjruoho
5728c506b8Sjruoho /* Local prototypes */
5828c506b8Sjruoho
5928c506b8Sjruoho static void
6028c506b8Sjruoho UtPadNameWithUnderscores (
6128c506b8Sjruoho char *NameSeg,
6228c506b8Sjruoho char *PaddedNameSeg);
6328c506b8Sjruoho
6428c506b8Sjruoho static void
6528c506b8Sjruoho UtAttachNameseg (
6628c506b8Sjruoho ACPI_PARSE_OBJECT *Op,
6728c506b8Sjruoho char *Name);
6828c506b8Sjruoho
695b948c02Schristos static void
705b948c02Schristos UtDisplayErrorSummary (
715b948c02Schristos UINT32 FileId);
725b948c02Schristos
7328c506b8Sjruoho
7449c2f1f4Schristos /*******************************************************************************
7549c2f1f4Schristos *
7649c2f1f4Schristos * FUNCTION: UtIsBigEndianMachine
7749c2f1f4Schristos *
7849c2f1f4Schristos * PARAMETERS: None
7949c2f1f4Schristos *
8049c2f1f4Schristos * RETURN: TRUE if machine is big endian
8149c2f1f4Schristos * FALSE if machine is little endian
8249c2f1f4Schristos *
8349c2f1f4Schristos * DESCRIPTION: Detect whether machine is little endian or big endian.
8449c2f1f4Schristos *
8549c2f1f4Schristos ******************************************************************************/
8649c2f1f4Schristos
8749c2f1f4Schristos UINT8
UtIsBigEndianMachine(void)8849c2f1f4Schristos UtIsBigEndianMachine (
8949c2f1f4Schristos void)
9049c2f1f4Schristos {
9149c2f1f4Schristos union {
9249c2f1f4Schristos UINT32 Integer;
9349c2f1f4Schristos UINT8 Bytes[4];
9449c2f1f4Schristos } Overlay = {0xFF000000};
9549c2f1f4Schristos
9649c2f1f4Schristos
9749c2f1f4Schristos return (Overlay.Bytes[0]); /* Returns 0xFF (TRUE) for big endian */
9849c2f1f4Schristos }
9949c2f1f4Schristos
10049c2f1f4Schristos
1012546ead2Schristos /*******************************************************************************
1022546ead2Schristos *
1032546ead2Schristos * FUNCTION: UtIsIdInteger
1042546ead2Schristos *
1052546ead2Schristos * PARAMETERS: Pointer to an ACPI ID (HID, CID) string
1062546ead2Schristos *
1072546ead2Schristos * RETURN: TRUE if string is an integer
1082546ead2Schristos * FALSE if string is not an integer
1092546ead2Schristos *
1102546ead2Schristos * DESCRIPTION: Determine whether the input ACPI ID string can be converted to
1112546ead2Schristos * an integer value.
1122546ead2Schristos *
1132546ead2Schristos ******************************************************************************/
1142546ead2Schristos
1152546ead2Schristos BOOLEAN
UtIsIdInteger(UINT8 * Target)1162546ead2Schristos UtIsIdInteger (
1172546ead2Schristos UINT8 *Target)
1182546ead2Schristos {
1192546ead2Schristos UINT32 i;
1202546ead2Schristos
1212546ead2Schristos
1222546ead2Schristos /* The first three characters of the string must be alphabetic */
1232546ead2Schristos
1242546ead2Schristos for (i = 0; i < 3; i++)
1252546ead2Schristos {
1262546ead2Schristos if (!isalpha ((int) Target[i]))
1272546ead2Schristos {
1282546ead2Schristos break;
1292546ead2Schristos }
1302546ead2Schristos }
1312546ead2Schristos
1322546ead2Schristos if (i < 3)
1332546ead2Schristos {
1342546ead2Schristos return (TRUE);
1352546ead2Schristos }
1362546ead2Schristos
1372546ead2Schristos return (FALSE);
1382546ead2Schristos }
1392546ead2Schristos
1402546ead2Schristos
14181bd9c9cSchristos /******************************************************************************
14281bd9c9cSchristos *
14381bd9c9cSchristos * FUNCTION: UtQueryForOverwrite
14481bd9c9cSchristos *
14581bd9c9cSchristos * PARAMETERS: Pathname - Output filename
14681bd9c9cSchristos *
14781bd9c9cSchristos * RETURN: TRUE if file does not exist or overwrite is authorized
14881bd9c9cSchristos *
14981bd9c9cSchristos * DESCRIPTION: Query for file overwrite if it already exists.
15081bd9c9cSchristos *
15181bd9c9cSchristos ******************************************************************************/
15281bd9c9cSchristos
15381bd9c9cSchristos BOOLEAN
UtQueryForOverwrite(char * Pathname)15481bd9c9cSchristos UtQueryForOverwrite (
15581bd9c9cSchristos char *Pathname)
15681bd9c9cSchristos {
15781bd9c9cSchristos struct stat StatInfo;
1581c663068Schristos int InChar;
15981bd9c9cSchristos
16081bd9c9cSchristos
16181bd9c9cSchristos if (!stat (Pathname, &StatInfo))
16281bd9c9cSchristos {
16381bd9c9cSchristos fprintf (stderr, "Target file \"%s\" already exists, overwrite? [y|n] ",
16481bd9c9cSchristos Pathname);
16581bd9c9cSchristos
1667ab6b89bSchristos InChar = fgetc (stdin);
1677ab6b89bSchristos if (InChar == '\n')
1687ab6b89bSchristos {
1697ab6b89bSchristos InChar = fgetc (stdin);
1707ab6b89bSchristos }
1717ab6b89bSchristos
1727ab6b89bSchristos if ((InChar != 'y') && (InChar != 'Y'))
17381bd9c9cSchristos {
17481bd9c9cSchristos return (FALSE);
17581bd9c9cSchristos }
17681bd9c9cSchristos }
17781bd9c9cSchristos
17881bd9c9cSchristos return (TRUE);
17981bd9c9cSchristos }
18081bd9c9cSchristos
18181bd9c9cSchristos
18228c506b8Sjruoho /*******************************************************************************
18328c506b8Sjruoho *
184a40a9998Schristos * FUNCTION: UtNodeIsDescendantOf
185a40a9998Schristos *
186a40a9998Schristos * PARAMETERS: Node1 - Child node
187a40a9998Schristos * Node2 - Possible parent node
188a40a9998Schristos *
189a40a9998Schristos * RETURN: Boolean
190a40a9998Schristos *
191a40a9998Schristos * DESCRIPTION: Returns TRUE if Node1 is a descendant of Node2. Otherwise,
192a40a9998Schristos * return FALSE. Note, we assume a NULL Node2 element to be the
193a40a9998Schristos * topmost (root) scope. All nodes are descendants of the root.
194a40a9998Schristos * Note: Nodes at the same level (siblings) are not considered
195a40a9998Schristos * descendants.
196a40a9998Schristos *
197a40a9998Schristos ******************************************************************************/
198a40a9998Schristos
199a40a9998Schristos BOOLEAN
UtNodeIsDescendantOf(ACPI_NAMESPACE_NODE * Node1,ACPI_NAMESPACE_NODE * Node2)200a40a9998Schristos UtNodeIsDescendantOf (
201a40a9998Schristos ACPI_NAMESPACE_NODE *Node1,
202a40a9998Schristos ACPI_NAMESPACE_NODE *Node2)
203a40a9998Schristos {
204a40a9998Schristos
205a40a9998Schristos if (Node1 == Node2)
206a40a9998Schristos {
207a40a9998Schristos return (FALSE);
208a40a9998Schristos }
209a40a9998Schristos
210a40a9998Schristos if (!Node2)
211a40a9998Schristos {
212a40a9998Schristos return (TRUE); /* All nodes descend from the root */
213a40a9998Schristos }
214a40a9998Schristos
215a40a9998Schristos /* Walk upward until the root is reached or parent is found */
216a40a9998Schristos
217a40a9998Schristos while (Node1)
218a40a9998Schristos {
219a40a9998Schristos if (Node1 == Node2)
220a40a9998Schristos {
221a40a9998Schristos return (TRUE);
222a40a9998Schristos }
223a40a9998Schristos
224a40a9998Schristos Node1 = Node1->Parent;
225a40a9998Schristos }
226a40a9998Schristos
227a40a9998Schristos return (FALSE);
228a40a9998Schristos }
229a40a9998Schristos
230a40a9998Schristos
231a40a9998Schristos /*******************************************************************************
232a40a9998Schristos *
2339ddb8508Schristos * FUNCTION: UtGetParentMethodNode
234a40a9998Schristos *
235a40a9998Schristos * PARAMETERS: Node - Namespace node for any object
236a40a9998Schristos *
237a40a9998Schristos * RETURN: Namespace node for the parent method
238a40a9998Schristos * NULL - object is not within a method
239a40a9998Schristos *
240a40a9998Schristos * DESCRIPTION: Find the parent (owning) method node for a namespace object
241a40a9998Schristos *
242a40a9998Schristos ******************************************************************************/
243a40a9998Schristos
2449ddb8508Schristos ACPI_NAMESPACE_NODE *
UtGetParentMethodNode(ACPI_NAMESPACE_NODE * Node)2459ddb8508Schristos UtGetParentMethodNode (
246a40a9998Schristos ACPI_NAMESPACE_NODE *Node)
247a40a9998Schristos {
248a40a9998Schristos ACPI_NAMESPACE_NODE *ParentNode;
249a40a9998Schristos
250a40a9998Schristos
251a40a9998Schristos if (!Node)
252a40a9998Schristos {
253a40a9998Schristos return (NULL);
254a40a9998Schristos }
255a40a9998Schristos
256a40a9998Schristos /* Walk upward until a method is found, or the root is reached */
257a40a9998Schristos
258a40a9998Schristos ParentNode = Node->Parent;
259a40a9998Schristos while (ParentNode)
260a40a9998Schristos {
261a40a9998Schristos if (ParentNode->Type == ACPI_TYPE_METHOD)
262a40a9998Schristos {
263a40a9998Schristos return (ParentNode);
264a40a9998Schristos }
265a40a9998Schristos
266a40a9998Schristos ParentNode = ParentNode->Parent;
267a40a9998Schristos }
268a40a9998Schristos
269a40a9998Schristos return (NULL); /* Object is not within a control method */
270a40a9998Schristos }
271a40a9998Schristos
272a40a9998Schristos
273a40a9998Schristos /*******************************************************************************
274a40a9998Schristos *
2759ddb8508Schristos * FUNCTION: UtGetParentMethodOp
2769ddb8508Schristos *
2779ddb8508Schristos * PARAMETERS: Op - Parse Op to be checked
2789ddb8508Schristos *
2799ddb8508Schristos * RETURN: Control method Op if found. NULL otherwise
2809ddb8508Schristos *
2819ddb8508Schristos * DESCRIPTION: Find the control method parent of a parse op. Returns NULL if
2829ddb8508Schristos * the input Op is not within a control method.
2839ddb8508Schristos *
2849ddb8508Schristos ******************************************************************************/
2859ddb8508Schristos
2869ddb8508Schristos ACPI_PARSE_OBJECT *
UtGetParentMethodOp(ACPI_PARSE_OBJECT * Op)2879ddb8508Schristos UtGetParentMethodOp (
2889ddb8508Schristos ACPI_PARSE_OBJECT *Op)
2899ddb8508Schristos {
2909ddb8508Schristos ACPI_PARSE_OBJECT *NextOp;
2919ddb8508Schristos
2929ddb8508Schristos
2939ddb8508Schristos NextOp = Op->Asl.Parent;
2949ddb8508Schristos while (NextOp)
2959ddb8508Schristos {
2969ddb8508Schristos if (NextOp->Asl.AmlOpcode == AML_METHOD_OP)
2979ddb8508Schristos {
2989ddb8508Schristos return (NextOp);
2999ddb8508Schristos }
3009ddb8508Schristos
3019ddb8508Schristos NextOp = NextOp->Asl.Parent;
3029ddb8508Schristos }
3039ddb8508Schristos
3049ddb8508Schristos return (NULL); /* No parent method found */
3059ddb8508Schristos }
3069ddb8508Schristos
3079ddb8508Schristos
3089ddb8508Schristos /*******************************************************************************
3099ddb8508Schristos *
310159c4e26Sjruoho * FUNCTION: UtDisplaySupportedTables
311159c4e26Sjruoho *
312159c4e26Sjruoho * PARAMETERS: None
313159c4e26Sjruoho *
314159c4e26Sjruoho * RETURN: None
315159c4e26Sjruoho *
316159c4e26Sjruoho * DESCRIPTION: Print all supported ACPI table names.
317159c4e26Sjruoho *
318159c4e26Sjruoho ******************************************************************************/
319159c4e26Sjruoho
320159c4e26Sjruoho void
UtDisplaySupportedTables(void)321159c4e26Sjruoho UtDisplaySupportedTables (
322159c4e26Sjruoho void)
323159c4e26Sjruoho {
3249b9ee194Schristos const AH_TABLE *TableData;
325a2c051a9Schristos UINT32 i;
326159c4e26Sjruoho
327159c4e26Sjruoho
328a2c051a9Schristos printf ("\nACPI tables supported by iASL version %8.8X:\n"
32986cbec8eSchristos " (Compiler, Disassembler, Template Generator)\n",
330a2c051a9Schristos ACPI_CA_VERSION);
331159c4e26Sjruoho
3329b9ee194Schristos /* All ACPI tables with the common table header */
333159c4e26Sjruoho
33486cbec8eSchristos printf ("\nKnown/Supported ACPI tables:\n");
3357efa3256Schristos for (TableData = AcpiGbl_SupportedTables, i = 1;
3369b9ee194Schristos TableData->Signature; TableData++, i++)
337159c4e26Sjruoho {
3389b9ee194Schristos printf ("%8u) %s %s\n", i,
3399b9ee194Schristos TableData->Signature, TableData->Description);
340159c4e26Sjruoho }
34186cbec8eSchristos
34286cbec8eSchristos printf ("\nTotal %u ACPI tables\n\n", i-1);
343159c4e26Sjruoho }
344159c4e26Sjruoho
345159c4e26Sjruoho
346159c4e26Sjruoho /*******************************************************************************
347159c4e26Sjruoho *
348a2c051a9Schristos * FUNCTION: UtDisplayConstantOpcodes
34928c506b8Sjruoho *
35028c506b8Sjruoho * PARAMETERS: None
35128c506b8Sjruoho *
35228c506b8Sjruoho * RETURN: None
35328c506b8Sjruoho *
35428c506b8Sjruoho * DESCRIPTION: Print AML opcodes that can be used in constant expressions.
35528c506b8Sjruoho *
35628c506b8Sjruoho ******************************************************************************/
35728c506b8Sjruoho
35828c506b8Sjruoho void
UtDisplayConstantOpcodes(void)35928c506b8Sjruoho UtDisplayConstantOpcodes (
36028c506b8Sjruoho void)
36128c506b8Sjruoho {
36228c506b8Sjruoho UINT32 i;
36328c506b8Sjruoho
36428c506b8Sjruoho
36528c506b8Sjruoho printf ("Constant expression opcode information\n\n");
36628c506b8Sjruoho
36728c506b8Sjruoho for (i = 0; i < sizeof (AcpiGbl_AmlOpInfo) / sizeof (ACPI_OPCODE_INFO); i++)
36828c506b8Sjruoho {
36928c506b8Sjruoho if (AcpiGbl_AmlOpInfo[i].Flags & AML_CONSTANT)
37028c506b8Sjruoho {
37128c506b8Sjruoho printf ("%s\n", AcpiGbl_AmlOpInfo[i].Name);
37228c506b8Sjruoho }
37328c506b8Sjruoho }
37428c506b8Sjruoho }
37528c506b8Sjruoho
37628c506b8Sjruoho
37728c506b8Sjruoho /*******************************************************************************
37828c506b8Sjruoho *
37928c506b8Sjruoho * FUNCTION: UtBeginEvent
38028c506b8Sjruoho *
38128c506b8Sjruoho * PARAMETERS: Name - Ascii name of this event
38228c506b8Sjruoho *
383a2c051a9Schristos * RETURN: Event number (integer index)
38428c506b8Sjruoho *
38528c506b8Sjruoho * DESCRIPTION: Saves the current time with this event
38628c506b8Sjruoho *
38728c506b8Sjruoho ******************************************************************************/
38828c506b8Sjruoho
38928c506b8Sjruoho UINT8
UtBeginEvent(char * Name)39028c506b8Sjruoho UtBeginEvent (
39128c506b8Sjruoho char *Name)
39228c506b8Sjruoho {
39328c506b8Sjruoho
39428c506b8Sjruoho if (AslGbl_NextEvent >= ASL_NUM_EVENTS)
39528c506b8Sjruoho {
39628c506b8Sjruoho AcpiOsPrintf ("Ran out of compiler event structs!\n");
39728c506b8Sjruoho return (AslGbl_NextEvent);
39828c506b8Sjruoho }
39928c506b8Sjruoho
40028c506b8Sjruoho /* Init event with current (start) time */
40128c506b8Sjruoho
40228c506b8Sjruoho AslGbl_Events[AslGbl_NextEvent].StartTime = AcpiOsGetTimer ();
40328c506b8Sjruoho AslGbl_Events[AslGbl_NextEvent].EventName = Name;
40428c506b8Sjruoho AslGbl_Events[AslGbl_NextEvent].Valid = TRUE;
40528c506b8Sjruoho return (AslGbl_NextEvent++);
40628c506b8Sjruoho }
40728c506b8Sjruoho
40828c506b8Sjruoho
40928c506b8Sjruoho /*******************************************************************************
41028c506b8Sjruoho *
41128c506b8Sjruoho * FUNCTION: UtEndEvent
41228c506b8Sjruoho *
41328c506b8Sjruoho * PARAMETERS: Event - Event number (integer index)
41428c506b8Sjruoho *
41528c506b8Sjruoho * RETURN: None
41628c506b8Sjruoho *
41728c506b8Sjruoho * DESCRIPTION: Saves the current time (end time) with this event
41828c506b8Sjruoho *
41928c506b8Sjruoho ******************************************************************************/
42028c506b8Sjruoho
42128c506b8Sjruoho void
UtEndEvent(UINT8 Event)42228c506b8Sjruoho UtEndEvent (
42328c506b8Sjruoho UINT8 Event)
42428c506b8Sjruoho {
42528c506b8Sjruoho
42628c506b8Sjruoho if (Event >= ASL_NUM_EVENTS)
42728c506b8Sjruoho {
42828c506b8Sjruoho return;
42928c506b8Sjruoho }
43028c506b8Sjruoho
43128c506b8Sjruoho /* Insert end time for event */
43228c506b8Sjruoho
43328c506b8Sjruoho AslGbl_Events[Event].EndTime = AcpiOsGetTimer ();
43428c506b8Sjruoho }
43528c506b8Sjruoho
43628c506b8Sjruoho
43728c506b8Sjruoho /*******************************************************************************
43828c506b8Sjruoho *
43928c506b8Sjruoho * FUNCTION: DbgPrint
44028c506b8Sjruoho *
44128c506b8Sjruoho * PARAMETERS: Type - Type of output
44228c506b8Sjruoho * Fmt - Printf format string
44328c506b8Sjruoho * ... - variable printf list
44428c506b8Sjruoho *
44528c506b8Sjruoho * RETURN: None
44628c506b8Sjruoho *
44728c506b8Sjruoho * DESCRIPTION: Conditional print statement. Prints to stderr only if the
44828c506b8Sjruoho * debug flag is set.
44928c506b8Sjruoho *
45028c506b8Sjruoho ******************************************************************************/
45128c506b8Sjruoho
45228c506b8Sjruoho void
DbgPrint(UINT32 Type,char * Fmt,...)45328c506b8Sjruoho DbgPrint (
45428c506b8Sjruoho UINT32 Type,
45528c506b8Sjruoho char *Fmt,
45628c506b8Sjruoho ...)
45728c506b8Sjruoho {
45828c506b8Sjruoho va_list Args;
45928c506b8Sjruoho
46028c506b8Sjruoho
4617efa3256Schristos if (!AslGbl_DebugFlag)
46228c506b8Sjruoho {
46328c506b8Sjruoho return;
46428c506b8Sjruoho }
46528c506b8Sjruoho
46628c506b8Sjruoho if ((Type == ASL_PARSE_OUTPUT) &&
46728c506b8Sjruoho (!(AslCompilerdebug)))
46828c506b8Sjruoho {
46928c506b8Sjruoho return;
47028c506b8Sjruoho }
47128c506b8Sjruoho
47212e03428Schristos va_start (Args, Fmt);
47328c506b8Sjruoho (void) vfprintf (stderr, Fmt, Args);
47428c506b8Sjruoho va_end (Args);
47528c506b8Sjruoho return;
47628c506b8Sjruoho }
47728c506b8Sjruoho
47828c506b8Sjruoho
47928c506b8Sjruoho /*******************************************************************************
48028c506b8Sjruoho *
48128c506b8Sjruoho * FUNCTION: UtSetParseOpName
48228c506b8Sjruoho *
483a2c051a9Schristos * PARAMETERS: Op - Parse op to be named.
48428c506b8Sjruoho *
48528c506b8Sjruoho * RETURN: None
48628c506b8Sjruoho *
48728c506b8Sjruoho * DESCRIPTION: Insert the ascii name of the parse opcode
48828c506b8Sjruoho *
48928c506b8Sjruoho ******************************************************************************/
49028c506b8Sjruoho
49128c506b8Sjruoho void
UtSetParseOpName(ACPI_PARSE_OBJECT * Op)49228c506b8Sjruoho UtSetParseOpName (
49328c506b8Sjruoho ACPI_PARSE_OBJECT *Op)
49428c506b8Sjruoho {
49528c506b8Sjruoho
496f45f09e8Schristos AcpiUtSafeStrncpy (Op->Asl.ParseOpName, UtGetOpName (Op->Asl.ParseOpcode),
49728c506b8Sjruoho ACPI_MAX_PARSEOP_NAME);
49828c506b8Sjruoho }
49928c506b8Sjruoho
50028c506b8Sjruoho
50128c506b8Sjruoho /*******************************************************************************
50228c506b8Sjruoho *
5035b948c02Schristos * FUNCTION: UtDisplayOneSummary
50428c506b8Sjruoho *
505*2c7d7e3cSchristos * PARAMETERS: FileID - ID of output file
50628c506b8Sjruoho *
50728c506b8Sjruoho * RETURN: None
50828c506b8Sjruoho *
5095b948c02Schristos * DESCRIPTION: Display compilation statistics for one input file
51028c506b8Sjruoho *
51128c506b8Sjruoho ******************************************************************************/
51228c506b8Sjruoho
51328c506b8Sjruoho void
UtDisplayOneSummary(UINT32 FileId,BOOLEAN DisplayErrorSummary)5145b948c02Schristos UtDisplayOneSummary (
5155b948c02Schristos UINT32 FileId,
5165b948c02Schristos BOOLEAN DisplayErrorSummary)
51728c506b8Sjruoho {
518a2c051a9Schristos UINT32 i;
5195b948c02Schristos ASL_GLOBAL_FILE_NODE *FileNode;
5207ab6b89bSchristos BOOLEAN DisplayAMLSummary;
521a2c051a9Schristos
52228c506b8Sjruoho
5237ab6b89bSchristos DisplayAMLSummary =
5247ab6b89bSchristos !AslGbl_PreprocessOnly && !AslGbl_ParserErrorDetected &&
5257ab6b89bSchristos ((AslGbl_ExceptionCount[ASL_ERROR] == 0) || AslGbl_IgnoreErrors) &&
5267ab6b89bSchristos AslGbl_Files[ASL_FILE_AML_OUTPUT].Handle;
5277ab6b89bSchristos
52828c506b8Sjruoho if (FileId != ASL_FILE_STDOUT)
52928c506b8Sjruoho {
53028c506b8Sjruoho /* Compiler name and version number */
53128c506b8Sjruoho
532660602a8Schristos FlPrintFile (FileId, "%s version %X [%s]\n\n",
533a43dcd2aSchristos ASL_COMPILER_NAME, (UINT32) ACPI_CA_VERSION, ACPI_DATE);
53428c506b8Sjruoho }
53528c506b8Sjruoho
536a2c051a9Schristos /* Summary of main input and output files */
537a2c051a9Schristos
5385b948c02Schristos FileNode = FlGetCurrentFileNode ();
5397ab6b89bSchristos
5405b948c02Schristos if (FileNode->ParserErrorDetected)
5415b948c02Schristos {
54228c506b8Sjruoho FlPrintFile (FileId,
5435b948c02Schristos "%-14s %s - Compilation aborted due to parser-detected syntax error(s)\n",
5447ab6b89bSchristos "Input file:", AslGbl_Files[ASL_FILE_INPUT].Filename);
5455b948c02Schristos }
5467ab6b89bSchristos else if (FileNode->FileType == ASL_INPUT_TYPE_ASCII_DATA)
5477ab6b89bSchristos {
5487ab6b89bSchristos FlPrintFile (FileId,
5497ab6b89bSchristos "%-14s %s - %7u bytes %6u fields %8u source lines\n",
5507ab6b89bSchristos "Table Input:",
5517ab6b89bSchristos AslGbl_Files[ASL_FILE_INPUT].Filename,
5527ab6b89bSchristos FileNode->OriginalInputFileSize, FileNode->TotalFields,
5537ab6b89bSchristos FileNode->TotalLineCount);
5547ab6b89bSchristos
5557ab6b89bSchristos FlPrintFile (FileId,
5567ab6b89bSchristos "%-14s %s - %7u bytes\n",
5577ab6b89bSchristos "Binary Output:",
5587ab6b89bSchristos AslGbl_Files[ASL_FILE_AML_OUTPUT].Filename, FileNode->OutputByteLength);
5597ab6b89bSchristos }
5607ab6b89bSchristos else if (FileNode->FileType == ASL_INPUT_TYPE_ASCII_ASL)
5615b948c02Schristos {
5625b948c02Schristos FlPrintFile (FileId,
5635b948c02Schristos "%-14s %s - %7u bytes %6u keywords %6u source lines\n",
564a2c051a9Schristos "ASL Input:",
5655b948c02Schristos AslGbl_Files[ASL_FILE_INPUT].Filename,
5665b948c02Schristos FileNode->OriginalInputFileSize,
5675b948c02Schristos FileNode->TotalKeywords,
5685b948c02Schristos FileNode->TotalLineCount);
56928c506b8Sjruoho
57028c506b8Sjruoho /* AML summary */
57128c506b8Sjruoho
5727ab6b89bSchristos if (DisplayAMLSummary)
5739b9ee194Schristos {
57428c506b8Sjruoho FlPrintFile (FileId,
5755b948c02Schristos "%-14s %s - %7u bytes %6u opcodes %6u named objects\n",
576a2c051a9Schristos "AML Output:",
5777efa3256Schristos AslGbl_Files[ASL_FILE_AML_OUTPUT].Filename,
57881bd9c9cSchristos FlGetFileSize (ASL_FILE_AML_OUTPUT),
5795b948c02Schristos FileNode->TotalExecutableOpcodes,
5805b948c02Schristos FileNode->TotalNamedObjects);
58128c506b8Sjruoho }
58228c506b8Sjruoho }
58328c506b8Sjruoho
584a2c051a9Schristos /* Display summary of any optional files */
585a2c051a9Schristos
586a2c051a9Schristos for (i = ASL_FILE_SOURCE_OUTPUT; i <= ASL_MAX_FILE_TYPE; i++)
587a2c051a9Schristos {
5887efa3256Schristos if (!AslGbl_Files[i].Filename || !AslGbl_Files[i].Handle)
589a2c051a9Schristos {
590a2c051a9Schristos continue;
591a2c051a9Schristos }
592a2c051a9Schristos
593a2c051a9Schristos /* .SRC is a temp file unless specifically requested */
594a2c051a9Schristos
5957efa3256Schristos if ((i == ASL_FILE_SOURCE_OUTPUT) && (!AslGbl_SourceOutputFlag))
596a2c051a9Schristos {
597a2c051a9Schristos continue;
598a2c051a9Schristos }
599a2c051a9Schristos
6009b9ee194Schristos /* .PRE is the preprocessor intermediate file */
601a2c051a9Schristos
6027efa3256Schristos if ((i == ASL_FILE_PREPROCESSOR) && (!AslGbl_KeepPreprocessorTempFile))
603a2c051a9Schristos {
604a2c051a9Schristos continue;
605a2c051a9Schristos }
606a2c051a9Schristos
6077ab6b89bSchristos FlPrintFile (FileId, "%-14s %s - %7u bytes\n",
6085b948c02Schristos AslGbl_FileDescs[i].ShortDescription,
6097efa3256Schristos AslGbl_Files[i].Filename, FlGetFileSize (i));
610a2c051a9Schristos }
611a2c051a9Schristos
6125b948c02Schristos
6135b948c02Schristos /*
6145b948c02Schristos * Optionally emit an error summary for a file. This is used to enhance the
6155b948c02Schristos * appearance of listing files.
6165b948c02Schristos */
6175b948c02Schristos if (DisplayErrorSummary)
6185b948c02Schristos {
6195b948c02Schristos UtDisplayErrorSummary (FileId);
6205b948c02Schristos }
6215b948c02Schristos }
6225b948c02Schristos
6235b948c02Schristos
6245b948c02Schristos /*******************************************************************************
6255b948c02Schristos *
6265b948c02Schristos * FUNCTION: UtDisplayErrorSummary
6275b948c02Schristos *
628*2c7d7e3cSchristos * PARAMETERS: FileID - ID of output file
6295b948c02Schristos *
6305b948c02Schristos * RETURN: None
6315b948c02Schristos *
6325b948c02Schristos * DESCRIPTION: Display compilation statistics for all input files
6335b948c02Schristos *
6345b948c02Schristos ******************************************************************************/
6355b948c02Schristos
6365b948c02Schristos static void
UtDisplayErrorSummary(UINT32 FileId)6375b948c02Schristos UtDisplayErrorSummary (
6385b948c02Schristos UINT32 FileId)
6395b948c02Schristos {
6405b948c02Schristos BOOLEAN ErrorDetected;
6415b948c02Schristos
6425b948c02Schristos
6435b948c02Schristos ErrorDetected = AslGbl_ParserErrorDetected ||
6445b948c02Schristos ((AslGbl_ExceptionCount[ASL_ERROR] > 0) && !AslGbl_IgnoreErrors);
6455b948c02Schristos
6465b948c02Schristos if (ErrorDetected)
6475b948c02Schristos {
6485b948c02Schristos FlPrintFile (FileId, "\nCompilation failed. ");
6495b948c02Schristos }
6505b948c02Schristos else
6515b948c02Schristos {
6525b948c02Schristos FlPrintFile (FileId, "\nCompilation successful. ");
6535b948c02Schristos }
65428c506b8Sjruoho
65528c506b8Sjruoho FlPrintFile (FileId,
6565b948c02Schristos "%u Errors, %u Warnings, %u Remarks",
6577efa3256Schristos AslGbl_ExceptionCount[ASL_ERROR],
6587efa3256Schristos AslGbl_ExceptionCount[ASL_WARNING] +
6597efa3256Schristos AslGbl_ExceptionCount[ASL_WARNING2] +
6607efa3256Schristos AslGbl_ExceptionCount[ASL_WARNING3],
6617efa3256Schristos AslGbl_ExceptionCount[ASL_REMARK]);
66228c506b8Sjruoho
6637efa3256Schristos if (AslGbl_FileType != ASL_INPUT_TYPE_ASCII_DATA)
66428c506b8Sjruoho {
6655b948c02Schristos if (AslGbl_ParserErrorDetected)
6665b948c02Schristos {
6675b948c02Schristos FlPrintFile (FileId,
6685b948c02Schristos "\nNo AML files were generated due to syntax error(s)\n");
6695b948c02Schristos return;
6705b948c02Schristos }
6715b948c02Schristos else if (ErrorDetected)
6725b948c02Schristos {
6735b948c02Schristos FlPrintFile (FileId,
6745b948c02Schristos "\nNo AML files were generated due to compiler error(s)\n");
6755b948c02Schristos return;
6765b948c02Schristos }
6775b948c02Schristos
678cb2bd8f0Schristos FlPrintFile (FileId, ", %u Optimizations",
6797efa3256Schristos AslGbl_ExceptionCount[ASL_OPTIMIZATION]);
680cb2bd8f0Schristos
6817efa3256Schristos if (AslGbl_TotalFolds)
682cb2bd8f0Schristos {
6837efa3256Schristos FlPrintFile (FileId, ", %u Constants Folded", AslGbl_TotalFolds);
684cb2bd8f0Schristos }
68528c506b8Sjruoho }
68628c506b8Sjruoho
68728c506b8Sjruoho FlPrintFile (FileId, "\n");
68828c506b8Sjruoho }
68928c506b8Sjruoho
69028c506b8Sjruoho
69128c506b8Sjruoho /*******************************************************************************
69228c506b8Sjruoho *
6935b948c02Schristos * FUNCTION: UtDisplaySummary
6945b948c02Schristos *
695*2c7d7e3cSchristos * PARAMETERS: FileID - ID of output file
6965b948c02Schristos *
6975b948c02Schristos * RETURN: None
6985b948c02Schristos *
6995b948c02Schristos * DESCRIPTION: Display compilation statistics for all input files
7005b948c02Schristos *
7015b948c02Schristos ******************************************************************************/
7025b948c02Schristos
7035b948c02Schristos void
UtDisplaySummary(UINT32 FileId)7045b948c02Schristos UtDisplaySummary (
7055b948c02Schristos UINT32 FileId)
7065b948c02Schristos {
7075b948c02Schristos ASL_GLOBAL_FILE_NODE *Current = AslGbl_FilesList;
7085b948c02Schristos
7095b948c02Schristos
7105b948c02Schristos while (Current)
7115b948c02Schristos {
7125b948c02Schristos switch (FlSwitchFileSet(Current->Files[ASL_FILE_INPUT].Filename))
7135b948c02Schristos {
7145b948c02Schristos case SWITCH_TO_SAME_FILE:
7155b948c02Schristos case SWITCH_TO_DIFFERENT_FILE:
7165b948c02Schristos
7175b948c02Schristos UtDisplayOneSummary (FileId, FALSE);
7185b948c02Schristos Current = Current->Next;
7195b948c02Schristos break;
7205b948c02Schristos
7215b948c02Schristos case FILE_NOT_FOUND:
7225b948c02Schristos default:
7235b948c02Schristos
7245b948c02Schristos Current = NULL;
7255b948c02Schristos break;
7265b948c02Schristos }
7275b948c02Schristos }
7285b948c02Schristos UtDisplayErrorSummary (FileId);
7295b948c02Schristos }
7305b948c02Schristos
7315b948c02Schristos /*******************************************************************************
7325b948c02Schristos *
733a2c051a9Schristos * FUNCTION: UtCheckIntegerRange
73428c506b8Sjruoho *
73528c506b8Sjruoho * PARAMETERS: Op - Integer parse node
73628c506b8Sjruoho * LowValue - Smallest allowed value
73728c506b8Sjruoho * HighValue - Largest allowed value
73828c506b8Sjruoho *
73928c506b8Sjruoho * RETURN: Op if OK, otherwise NULL
74028c506b8Sjruoho *
74128c506b8Sjruoho * DESCRIPTION: Check integer for an allowable range
74228c506b8Sjruoho *
74328c506b8Sjruoho ******************************************************************************/
74428c506b8Sjruoho
74528c506b8Sjruoho ACPI_PARSE_OBJECT *
UtCheckIntegerRange(ACPI_PARSE_OBJECT * Op,UINT32 LowValue,UINT32 HighValue)74628c506b8Sjruoho UtCheckIntegerRange (
74728c506b8Sjruoho ACPI_PARSE_OBJECT *Op,
74828c506b8Sjruoho UINT32 LowValue,
74928c506b8Sjruoho UINT32 HighValue)
75028c506b8Sjruoho {
75128c506b8Sjruoho
75228c506b8Sjruoho if (!Op)
75328c506b8Sjruoho {
754a2c051a9Schristos return (NULL);
75528c506b8Sjruoho }
75628c506b8Sjruoho
757a2c051a9Schristos if ((Op->Asl.Value.Integer < LowValue) ||
758a2c051a9Schristos (Op->Asl.Value.Integer > HighValue))
75928c506b8Sjruoho {
7607efa3256Schristos snprintf (AslGbl_MsgBuffer, sizeof(AslGbl_MsgBuffer), "0x%X, allowable: 0x%X-0x%X",
761a2c051a9Schristos (UINT32) Op->Asl.Value.Integer, LowValue, HighValue);
762a2c051a9Schristos
7637efa3256Schristos AslError (ASL_ERROR, ASL_MSG_RANGE, Op, AslGbl_MsgBuffer);
764a2c051a9Schristos return (NULL);
76528c506b8Sjruoho }
76628c506b8Sjruoho
767a2c051a9Schristos return (Op);
76828c506b8Sjruoho }
76928c506b8Sjruoho
77028c506b8Sjruoho
77128c506b8Sjruoho /*******************************************************************************
77228c506b8Sjruoho *
77328c506b8Sjruoho * FUNCTION: UtInternalizeName
77428c506b8Sjruoho *
77528c506b8Sjruoho * PARAMETERS: ExternalName - Name to convert
77628c506b8Sjruoho * ConvertedName - Where the converted name is returned
77728c506b8Sjruoho *
77828c506b8Sjruoho * RETURN: Status
77928c506b8Sjruoho *
78028c506b8Sjruoho * DESCRIPTION: Convert an external (ASL) name to an internal (AML) name
78128c506b8Sjruoho *
78228c506b8Sjruoho ******************************************************************************/
78328c506b8Sjruoho
78428c506b8Sjruoho ACPI_STATUS
UtInternalizeName(char * ExternalName,char ** ConvertedName)78528c506b8Sjruoho UtInternalizeName (
78628c506b8Sjruoho char *ExternalName,
78728c506b8Sjruoho char **ConvertedName)
78828c506b8Sjruoho {
78928c506b8Sjruoho ACPI_NAMESTRING_INFO Info;
79028c506b8Sjruoho ACPI_STATUS Status;
79128c506b8Sjruoho
79228c506b8Sjruoho
79328c506b8Sjruoho if (!ExternalName)
79428c506b8Sjruoho {
79528c506b8Sjruoho return (AE_OK);
79628c506b8Sjruoho }
79728c506b8Sjruoho
79828c506b8Sjruoho /* Get the length of the new internal name */
79928c506b8Sjruoho
80028c506b8Sjruoho Info.ExternalName = ExternalName;
80128c506b8Sjruoho AcpiNsGetInternalNameLength (&Info);
80228c506b8Sjruoho
80328c506b8Sjruoho /* We need a segment to store the internal name */
80428c506b8Sjruoho
80525666a51Schristos Info.InternalName = UtLocalCacheCalloc (Info.Length);
80628c506b8Sjruoho
80728c506b8Sjruoho /* Build the name */
80828c506b8Sjruoho
80928c506b8Sjruoho Status = AcpiNsBuildInternalName (&Info);
81028c506b8Sjruoho if (ACPI_FAILURE (Status))
81128c506b8Sjruoho {
81228c506b8Sjruoho return (Status);
81328c506b8Sjruoho }
81428c506b8Sjruoho
81528c506b8Sjruoho *ConvertedName = Info.InternalName;
81628c506b8Sjruoho return (AE_OK);
81728c506b8Sjruoho }
81828c506b8Sjruoho
81928c506b8Sjruoho
82028c506b8Sjruoho /*******************************************************************************
82128c506b8Sjruoho *
82228c506b8Sjruoho * FUNCTION: UtPadNameWithUnderscores
82328c506b8Sjruoho *
82428c506b8Sjruoho * PARAMETERS: NameSeg - Input nameseg
82528c506b8Sjruoho * PaddedNameSeg - Output padded nameseg
82628c506b8Sjruoho *
82728c506b8Sjruoho * RETURN: Padded nameseg.
82828c506b8Sjruoho *
82928c506b8Sjruoho * DESCRIPTION: Pads a NameSeg with underscores if necessary to form a full
83028c506b8Sjruoho * ACPI_NAME.
83128c506b8Sjruoho *
83228c506b8Sjruoho ******************************************************************************/
83328c506b8Sjruoho
83428c506b8Sjruoho static void
UtPadNameWithUnderscores(char * NameSeg,char * PaddedNameSeg)83528c506b8Sjruoho UtPadNameWithUnderscores (
83628c506b8Sjruoho char *NameSeg,
83728c506b8Sjruoho char *PaddedNameSeg)
83828c506b8Sjruoho {
83928c506b8Sjruoho UINT32 i;
84028c506b8Sjruoho
84128c506b8Sjruoho
8425b948c02Schristos for (i = 0; (i < ACPI_NAMESEG_SIZE); i++)
84328c506b8Sjruoho {
84428c506b8Sjruoho if (*NameSeg)
84528c506b8Sjruoho {
84628c506b8Sjruoho *PaddedNameSeg = *NameSeg;
84728c506b8Sjruoho NameSeg++;
84828c506b8Sjruoho }
84928c506b8Sjruoho else
85028c506b8Sjruoho {
85128c506b8Sjruoho *PaddedNameSeg = '_';
85228c506b8Sjruoho }
85381bd9c9cSchristos
85428c506b8Sjruoho PaddedNameSeg++;
85528c506b8Sjruoho }
85628c506b8Sjruoho }
85728c506b8Sjruoho
85828c506b8Sjruoho
85928c506b8Sjruoho /*******************************************************************************
86028c506b8Sjruoho *
86128c506b8Sjruoho * FUNCTION: UtAttachNameseg
86228c506b8Sjruoho *
86328c506b8Sjruoho * PARAMETERS: Op - Parent parse node
86428c506b8Sjruoho * Name - Full ExternalName
86528c506b8Sjruoho *
86628c506b8Sjruoho * RETURN: None; Sets the NameSeg field in parent node
86728c506b8Sjruoho *
86828c506b8Sjruoho * DESCRIPTION: Extract the last nameseg of the ExternalName and store it
86928c506b8Sjruoho * in the NameSeg field of the Op.
87028c506b8Sjruoho *
87128c506b8Sjruoho ******************************************************************************/
87228c506b8Sjruoho
87328c506b8Sjruoho static void
UtAttachNameseg(ACPI_PARSE_OBJECT * Op,char * Name)87428c506b8Sjruoho UtAttachNameseg (
87528c506b8Sjruoho ACPI_PARSE_OBJECT *Op,
87628c506b8Sjruoho char *Name)
87728c506b8Sjruoho {
87828c506b8Sjruoho char *NameSeg;
87928c506b8Sjruoho char PaddedNameSeg[4];
88028c506b8Sjruoho
88128c506b8Sjruoho
88228c506b8Sjruoho if (!Name)
88328c506b8Sjruoho {
88428c506b8Sjruoho return;
88528c506b8Sjruoho }
88628c506b8Sjruoho
88728c506b8Sjruoho /* Look for the last dot in the namepath */
88828c506b8Sjruoho
88928c506b8Sjruoho NameSeg = strrchr (Name, '.');
89028c506b8Sjruoho if (NameSeg)
89128c506b8Sjruoho {
89228c506b8Sjruoho /* Found last dot, we have also found the final nameseg */
89328c506b8Sjruoho
89428c506b8Sjruoho NameSeg++;
89528c506b8Sjruoho UtPadNameWithUnderscores (NameSeg, PaddedNameSeg);
89628c506b8Sjruoho }
89728c506b8Sjruoho else
89828c506b8Sjruoho {
89928c506b8Sjruoho /* No dots in the namepath, there is only a single nameseg. */
90028c506b8Sjruoho /* Handle prefixes */
90128c506b8Sjruoho
902a2c051a9Schristos while (ACPI_IS_ROOT_PREFIX (*Name) ||
903a2c051a9Schristos ACPI_IS_PARENT_PREFIX (*Name))
90428c506b8Sjruoho {
90528c506b8Sjruoho Name++;
90628c506b8Sjruoho }
90728c506b8Sjruoho
908a2c051a9Schristos /* Remaining string should be one single nameseg */
90928c506b8Sjruoho
91028c506b8Sjruoho UtPadNameWithUnderscores (Name, PaddedNameSeg);
91128c506b8Sjruoho }
91228c506b8Sjruoho
9135b948c02Schristos ACPI_COPY_NAMESEG (Op->Asl.NameSeg, PaddedNameSeg);
91428c506b8Sjruoho }
91528c506b8Sjruoho
91628c506b8Sjruoho
91728c506b8Sjruoho /*******************************************************************************
91828c506b8Sjruoho *
91928c506b8Sjruoho * FUNCTION: UtAttachNamepathToOwner
92028c506b8Sjruoho *
92128c506b8Sjruoho * PARAMETERS: Op - Parent parse node
92228c506b8Sjruoho * NameOp - Node that contains the name
92328c506b8Sjruoho *
92428c506b8Sjruoho * RETURN: Sets the ExternalName and Namepath in the parent node
92528c506b8Sjruoho *
92628c506b8Sjruoho * DESCRIPTION: Store the name in two forms in the parent node: The original
92728c506b8Sjruoho * (external) name, and the internalized name that is used within
92828c506b8Sjruoho * the ACPI namespace manager.
92928c506b8Sjruoho *
93028c506b8Sjruoho ******************************************************************************/
93128c506b8Sjruoho
93228c506b8Sjruoho void
UtAttachNamepathToOwner(ACPI_PARSE_OBJECT * Op,ACPI_PARSE_OBJECT * NameOp)93328c506b8Sjruoho UtAttachNamepathToOwner (
93428c506b8Sjruoho ACPI_PARSE_OBJECT *Op,
93528c506b8Sjruoho ACPI_PARSE_OBJECT *NameOp)
93628c506b8Sjruoho {
93728c506b8Sjruoho ACPI_STATUS Status;
93828c506b8Sjruoho
93928c506b8Sjruoho
94028c506b8Sjruoho /* Full external path */
94128c506b8Sjruoho
94228c506b8Sjruoho Op->Asl.ExternalName = NameOp->Asl.Value.String;
94328c506b8Sjruoho
94428c506b8Sjruoho /* Save the NameOp for possible error reporting later */
94528c506b8Sjruoho
94628c506b8Sjruoho Op->Asl.ParentMethod = (void *) NameOp;
94728c506b8Sjruoho
94828c506b8Sjruoho /* Last nameseg of the path */
94928c506b8Sjruoho
95028c506b8Sjruoho UtAttachNameseg (Op, Op->Asl.ExternalName);
95128c506b8Sjruoho
95228c506b8Sjruoho /* Create internalized path */
95328c506b8Sjruoho
95428c506b8Sjruoho Status = UtInternalizeName (NameOp->Asl.Value.String, &Op->Asl.Namepath);
95528c506b8Sjruoho if (ACPI_FAILURE (Status))
95628c506b8Sjruoho {
95728c506b8Sjruoho /* TBD: abort on no memory */
95828c506b8Sjruoho }
95928c506b8Sjruoho }
96028c506b8Sjruoho
96128c506b8Sjruoho
96228c506b8Sjruoho /*******************************************************************************
96328c506b8Sjruoho *
9647ab6b89bSchristos * FUNCTION: UtNameContainsAllPrefix
9657ab6b89bSchristos *
9667ab6b89bSchristos * PARAMETERS: Op - Op containing NameString
9677ab6b89bSchristos *
9687ab6b89bSchristos * RETURN: NameString consists of all ^ characters
9697ab6b89bSchristos *
9707ab6b89bSchristos * DESCRIPTION: Determine if this Op contains a name segment that consists of
9717ab6b89bSchristos * all '^' characters.
9727ab6b89bSchristos *
9737ab6b89bSchristos ******************************************************************************/
9747ab6b89bSchristos
9757ab6b89bSchristos BOOLEAN
UtNameContainsAllPrefix(ACPI_PARSE_OBJECT * Op)9767ab6b89bSchristos UtNameContainsAllPrefix (
9777ab6b89bSchristos ACPI_PARSE_OBJECT *Op)
9787ab6b89bSchristos {
9797ab6b89bSchristos UINT32 Length = Op->Asl.AmlLength;
9807ab6b89bSchristos UINT32 i;
9817ab6b89bSchristos
9827ab6b89bSchristos for (i = 0; i < Length; i++)
9837ab6b89bSchristos {
9847ab6b89bSchristos if (Op->Asl.Value.String[i] != '^')
9857ab6b89bSchristos {
9867ab6b89bSchristos return (FALSE);
9877ab6b89bSchristos }
9887ab6b89bSchristos }
9897ab6b89bSchristos
9907ab6b89bSchristos return (TRUE);
9917ab6b89bSchristos }
9927ab6b89bSchristos
9937ab6b89bSchristos /*******************************************************************************
9947ab6b89bSchristos *
99528c506b8Sjruoho * FUNCTION: UtDoConstant
99628c506b8Sjruoho *
997ae01dbf5Schristos * PARAMETERS: String - Hex/Decimal/Octal
99828c506b8Sjruoho *
99928c506b8Sjruoho * RETURN: Converted Integer
100028c506b8Sjruoho *
1001ae01dbf5Schristos * DESCRIPTION: Convert a string to an integer, with overflow/error checking.
100228c506b8Sjruoho *
100328c506b8Sjruoho ******************************************************************************/
100428c506b8Sjruoho
100528c506b8Sjruoho UINT64
UtDoConstant(char * String)100628c506b8Sjruoho UtDoConstant (
100728c506b8Sjruoho char *String)
100828c506b8Sjruoho {
100928c506b8Sjruoho ACPI_STATUS Status;
1010ae01dbf5Schristos UINT64 ConvertedInteger;
1011b558e860Schristos char ErrBuf[128];
1012b558e860Schristos const ACPI_EXCEPTION_INFO *ExceptionInfo;
101328c506b8Sjruoho
101428c506b8Sjruoho
1015ae01dbf5Schristos Status = AcpiUtStrtoul64 (String, &ConvertedInteger);
101628c506b8Sjruoho if (ACPI_FAILURE (Status))
101728c506b8Sjruoho {
1018b558e860Schristos ExceptionInfo = AcpiUtValidateException ((ACPI_STATUS) Status);
1019b558e860Schristos snprintf (ErrBuf, sizeof(ErrBuf), " %s while converting to 64-bit integer",
1020b558e860Schristos ExceptionInfo->Description);
1021ae01dbf5Schristos
10227efa3256Schristos AslCommonError (ASL_ERROR, ASL_MSG_SYNTAX, AslGbl_CurrentLineNumber,
10237efa3256Schristos AslGbl_LogicalLineNumber, AslGbl_CurrentLineOffset,
10247efa3256Schristos AslGbl_CurrentColumn, AslGbl_Files[ASL_FILE_INPUT].Filename, ErrBuf);
102528c506b8Sjruoho }
102628c506b8Sjruoho
1027ae01dbf5Schristos return (ConvertedInteger);
102828c506b8Sjruoho }
10297ab6b89bSchristos
10307ab6b89bSchristos
10317ab6b89bSchristos /******************************************************************************
10327ab6b89bSchristos *
10337ab6b89bSchristos * FUNCTION: AcpiUtStrdup
10347ab6b89bSchristos *
10357ab6b89bSchristos * PARAMETERS: String1 - string to duplicate
10367ab6b89bSchristos *
10377ab6b89bSchristos * RETURN: int that signifies string relationship. Zero means strings
10387ab6b89bSchristos * are equal.
10397ab6b89bSchristos *
10407ab6b89bSchristos * DESCRIPTION: Duplicate the string using UtCacheAlloc to avoid manual memory
10417ab6b89bSchristos * reclamation.
10427ab6b89bSchristos *
10437ab6b89bSchristos ******************************************************************************/
10447ab6b89bSchristos
10457ab6b89bSchristos char *
AcpiUtStrdup(char * String)10467ab6b89bSchristos AcpiUtStrdup (
10477ab6b89bSchristos char *String)
10487ab6b89bSchristos {
10497ab6b89bSchristos char *NewString = (char *) UtLocalCalloc (strlen (String) + 1);
10507ab6b89bSchristos
10517ab6b89bSchristos
10527ab6b89bSchristos strcpy (NewString, String);
10537ab6b89bSchristos return (NewString);
10547ab6b89bSchristos }
10557ab6b89bSchristos
10567ab6b89bSchristos
10577ab6b89bSchristos /******************************************************************************
10587ab6b89bSchristos *
10597ab6b89bSchristos * FUNCTION: AcpiUtStrcat
10607ab6b89bSchristos *
10617ab6b89bSchristos * PARAMETERS: String1
10627ab6b89bSchristos * String2
10637ab6b89bSchristos *
10647ab6b89bSchristos * RETURN: New string with String1 concatenated with String2
10657ab6b89bSchristos *
10667ab6b89bSchristos * DESCRIPTION: Concatenate string1 and string2
10677ab6b89bSchristos *
10687ab6b89bSchristos ******************************************************************************/
10697ab6b89bSchristos
10707ab6b89bSchristos char *
AcpiUtStrcat(char * String1,char * String2)10717ab6b89bSchristos AcpiUtStrcat (
10727ab6b89bSchristos char *String1,
10737ab6b89bSchristos char *String2)
10747ab6b89bSchristos {
10757ab6b89bSchristos UINT32 String1Length = strlen (String1);
10767ab6b89bSchristos char *NewString = (char *) UtLocalCalloc (strlen (String1) + strlen (String2) + 1);
10777ab6b89bSchristos
10787ab6b89bSchristos strcpy (NewString, String1);
10797ab6b89bSchristos strcpy (NewString + String1Length, String2);
10807ab6b89bSchristos return (NewString);
10817ab6b89bSchristos }
1082