10b94ba42SJung-uk Kim /******************************************************************************
20b94ba42SJung-uk Kim *
30b94ba42SJung-uk Kim * Module Name: dtexpress.c - Support for integer expressions and labels
40b94ba42SJung-uk Kim *
50b94ba42SJung-uk Kim *****************************************************************************/
60b94ba42SJung-uk Kim
70d84335fSJung-uk Kim /******************************************************************************
80d84335fSJung-uk Kim *
90d84335fSJung-uk Kim * 1. Copyright Notice
100d84335fSJung-uk Kim *
11*58308fadSJung-uk Kim * Some or all of this work - Copyright (c) 1999 - 2025, Intel Corp.
120b94ba42SJung-uk Kim * All rights reserved.
130b94ba42SJung-uk Kim *
140d84335fSJung-uk Kim * 2. License
150d84335fSJung-uk Kim *
160d84335fSJung-uk Kim * 2.1. This is your license from Intel Corp. under its intellectual property
170d84335fSJung-uk Kim * rights. You may have additional license terms from the party that provided
180d84335fSJung-uk Kim * you this software, covering your right to use that party's intellectual
190d84335fSJung-uk Kim * property rights.
200d84335fSJung-uk Kim *
210d84335fSJung-uk Kim * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
220d84335fSJung-uk Kim * copy of the source code appearing in this file ("Covered Code") an
230d84335fSJung-uk Kim * irrevocable, perpetual, worldwide license under Intel's copyrights in the
240d84335fSJung-uk Kim * base code distributed originally by Intel ("Original Intel Code") to copy,
250d84335fSJung-uk Kim * make derivatives, distribute, use and display any portion of the Covered
260d84335fSJung-uk Kim * Code in any form, with the right to sublicense such rights; and
270d84335fSJung-uk Kim *
280d84335fSJung-uk Kim * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
290d84335fSJung-uk Kim * license (with the right to sublicense), under only those claims of Intel
300d84335fSJung-uk Kim * patents that are infringed by the Original Intel Code, to make, use, sell,
310d84335fSJung-uk Kim * offer to sell, and import the Covered Code and derivative works thereof
320d84335fSJung-uk Kim * solely to the minimum extent necessary to exercise the above copyright
330d84335fSJung-uk Kim * license, and in no event shall the patent license extend to any additions
340d84335fSJung-uk Kim * to or modifications of the Original Intel Code. No other license or right
350d84335fSJung-uk Kim * is granted directly or by implication, estoppel or otherwise;
360d84335fSJung-uk Kim *
370d84335fSJung-uk Kim * The above copyright and patent license is granted only if the following
380d84335fSJung-uk Kim * conditions are met:
390d84335fSJung-uk Kim *
400d84335fSJung-uk Kim * 3. Conditions
410d84335fSJung-uk Kim *
420d84335fSJung-uk Kim * 3.1. Redistribution of Source with Rights to Further Distribute Source.
430d84335fSJung-uk Kim * Redistribution of source code of any substantial portion of the Covered
440d84335fSJung-uk Kim * Code or modification with rights to further distribute source must include
450d84335fSJung-uk Kim * the above Copyright Notice, the above License, this list of Conditions,
460d84335fSJung-uk Kim * and the following Disclaimer and Export Compliance provision. In addition,
470d84335fSJung-uk Kim * Licensee must cause all Covered Code to which Licensee contributes to
480d84335fSJung-uk Kim * contain a file documenting the changes Licensee made to create that Covered
490d84335fSJung-uk Kim * Code and the date of any change. Licensee must include in that file the
500d84335fSJung-uk Kim * documentation of any changes made by any predecessor Licensee. Licensee
510d84335fSJung-uk Kim * must include a prominent statement that the modification is derived,
520d84335fSJung-uk Kim * directly or indirectly, from Original Intel Code.
530d84335fSJung-uk Kim *
540d84335fSJung-uk Kim * 3.2. Redistribution of Source with no Rights to Further Distribute Source.
550d84335fSJung-uk Kim * Redistribution of source code of any substantial portion of the Covered
560d84335fSJung-uk Kim * Code or modification without rights to further distribute source must
570d84335fSJung-uk Kim * include the following Disclaimer and Export Compliance provision in the
580d84335fSJung-uk Kim * documentation and/or other materials provided with distribution. In
590d84335fSJung-uk Kim * addition, Licensee may not authorize further sublicense of source of any
600d84335fSJung-uk Kim * portion of the Covered Code, and must include terms to the effect that the
610d84335fSJung-uk Kim * license from Licensee to its licensee is limited to the intellectual
620d84335fSJung-uk Kim * property embodied in the software Licensee provides to its licensee, and
630d84335fSJung-uk Kim * not to intellectual property embodied in modifications its licensee may
640d84335fSJung-uk Kim * make.
650d84335fSJung-uk Kim *
660d84335fSJung-uk Kim * 3.3. Redistribution of Executable. Redistribution in executable form of any
670d84335fSJung-uk Kim * substantial portion of the Covered Code or modification must reproduce the
680d84335fSJung-uk Kim * above Copyright Notice, and the following Disclaimer and Export Compliance
690d84335fSJung-uk Kim * provision in the documentation and/or other materials provided with the
700d84335fSJung-uk Kim * distribution.
710d84335fSJung-uk Kim *
720d84335fSJung-uk Kim * 3.4. Intel retains all right, title, and interest in and to the Original
730d84335fSJung-uk Kim * Intel Code.
740d84335fSJung-uk Kim *
750d84335fSJung-uk Kim * 3.5. Neither the name Intel nor any other trademark owned or controlled by
760d84335fSJung-uk Kim * Intel shall be used in advertising or otherwise to promote the sale, use or
770d84335fSJung-uk Kim * other dealings in products derived from or relating to the Covered Code
780d84335fSJung-uk Kim * without prior written authorization from Intel.
790d84335fSJung-uk Kim *
800d84335fSJung-uk Kim * 4. Disclaimer and Export Compliance
810d84335fSJung-uk Kim *
820d84335fSJung-uk Kim * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
830d84335fSJung-uk Kim * HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
840d84335fSJung-uk Kim * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE,
850d84335fSJung-uk Kim * INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY
860d84335fSJung-uk Kim * UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY
870d84335fSJung-uk Kim * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
880d84335fSJung-uk Kim * PARTICULAR PURPOSE.
890d84335fSJung-uk Kim *
900d84335fSJung-uk Kim * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
910d84335fSJung-uk Kim * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
920d84335fSJung-uk Kim * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
930d84335fSJung-uk Kim * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
940d84335fSJung-uk Kim * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
950d84335fSJung-uk Kim * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS
960d84335fSJung-uk Kim * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
970d84335fSJung-uk Kim * LIMITED REMEDY.
980d84335fSJung-uk Kim *
990d84335fSJung-uk Kim * 4.3. Licensee shall not export, either directly or indirectly, any of this
1000d84335fSJung-uk Kim * software or system incorporating such software without first obtaining any
1010d84335fSJung-uk Kim * required license or other approval from the U. S. Department of Commerce or
1020d84335fSJung-uk Kim * any other agency or department of the United States Government. In the
1030d84335fSJung-uk Kim * event Licensee exports any such software from the United States or
1040d84335fSJung-uk Kim * re-exports any such software from a foreign destination, Licensee shall
1050d84335fSJung-uk Kim * ensure that the distribution and export/re-export of the software is in
1060d84335fSJung-uk Kim * compliance with all laws, regulations, orders, or other restrictions of the
1070d84335fSJung-uk Kim * U.S. Export Administration Regulations. Licensee agrees that neither it nor
1080d84335fSJung-uk Kim * any of its subsidiaries will export/re-export any technical data, process,
1090d84335fSJung-uk Kim * software, or service, directly or indirectly, to any country for which the
1100d84335fSJung-uk Kim * United States government or any agency thereof requires an export license,
1110d84335fSJung-uk Kim * other governmental approval, or letter of assurance, without first obtaining
1120d84335fSJung-uk Kim * such license, approval or letter.
1130d84335fSJung-uk Kim *
1140d84335fSJung-uk Kim *****************************************************************************
1150d84335fSJung-uk Kim *
1160d84335fSJung-uk Kim * Alternatively, you may choose to be licensed under the terms of the
1170d84335fSJung-uk Kim * following license:
1180d84335fSJung-uk Kim *
1190b94ba42SJung-uk Kim * Redistribution and use in source and binary forms, with or without
1200b94ba42SJung-uk Kim * modification, are permitted provided that the following conditions
1210b94ba42SJung-uk Kim * are met:
1220b94ba42SJung-uk Kim * 1. Redistributions of source code must retain the above copyright
1230b94ba42SJung-uk Kim * notice, this list of conditions, and the following disclaimer,
1240b94ba42SJung-uk Kim * without modification.
1250b94ba42SJung-uk Kim * 2. Redistributions in binary form must reproduce at minimum a disclaimer
1260b94ba42SJung-uk Kim * substantially similar to the "NO WARRANTY" disclaimer below
1270b94ba42SJung-uk Kim * ("Disclaimer") and any redistribution must be conditioned upon
1280b94ba42SJung-uk Kim * including a substantially similar Disclaimer requirement for further
1290b94ba42SJung-uk Kim * binary redistribution.
1300b94ba42SJung-uk Kim * 3. Neither the names of the above-listed copyright holders nor the names
1310b94ba42SJung-uk Kim * of any contributors may be used to endorse or promote products derived
1320b94ba42SJung-uk Kim * from this software without specific prior written permission.
1330b94ba42SJung-uk Kim *
1340d84335fSJung-uk Kim * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
1350d84335fSJung-uk Kim * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
1360d84335fSJung-uk Kim * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
1370d84335fSJung-uk Kim * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
1380d84335fSJung-uk Kim * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
1390d84335fSJung-uk Kim * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
1400d84335fSJung-uk Kim * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
1410d84335fSJung-uk Kim * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
1420d84335fSJung-uk Kim * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
1430d84335fSJung-uk Kim * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
1440d84335fSJung-uk Kim * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
1450d84335fSJung-uk Kim *
1460d84335fSJung-uk Kim * Alternatively, you may choose to be licensed under the terms of the
1470b94ba42SJung-uk Kim * GNU General Public License ("GPL") version 2 as published by the Free
1480b94ba42SJung-uk Kim * Software Foundation.
1490b94ba42SJung-uk Kim *
1500d84335fSJung-uk Kim *****************************************************************************/
1510b94ba42SJung-uk Kim
1520b94ba42SJung-uk Kim #include <contrib/dev/acpica/compiler/aslcompiler.h>
153d052a1ccSJung-uk Kim #include "dtparser.y.h"
1540b94ba42SJung-uk Kim
1550b94ba42SJung-uk Kim #define _COMPONENT DT_COMPILER
1560b94ba42SJung-uk Kim ACPI_MODULE_NAME ("dtexpress")
1570b94ba42SJung-uk Kim
1580b94ba42SJung-uk Kim
1590b94ba42SJung-uk Kim /* Local prototypes */
1600b94ba42SJung-uk Kim
1610b94ba42SJung-uk Kim static void
1620b94ba42SJung-uk Kim DtInsertLabelField (
1630b94ba42SJung-uk Kim DT_FIELD *Field);
1640b94ba42SJung-uk Kim
1650b94ba42SJung-uk Kim static DT_FIELD *
1660b94ba42SJung-uk Kim DtLookupLabel (
1670b94ba42SJung-uk Kim char *Name);
1680b94ba42SJung-uk Kim
169d052a1ccSJung-uk Kim /* Global used for errors during parse and related functions */
170d052a1ccSJung-uk Kim
1716f1f1a63SJung-uk Kim DT_FIELD *AslGbl_CurrentField;
172d052a1ccSJung-uk Kim
1730b94ba42SJung-uk Kim
1740b94ba42SJung-uk Kim /******************************************************************************
1750b94ba42SJung-uk Kim *
1760b94ba42SJung-uk Kim * FUNCTION: DtResolveIntegerExpression
1770b94ba42SJung-uk Kim *
1780b94ba42SJung-uk Kim * PARAMETERS: Field - Field object with Integer expression
179d052a1ccSJung-uk Kim * ReturnValue - Where the integer is returned
1800b94ba42SJung-uk Kim *
181d052a1ccSJung-uk Kim * RETURN: Status, and the resolved 64-bit integer value
1820b94ba42SJung-uk Kim *
1830b94ba42SJung-uk Kim * DESCRIPTION: Resolve an integer expression to a single value. Supports
184d052a1ccSJung-uk Kim * both integer constants and labels.
1850b94ba42SJung-uk Kim *
1860b94ba42SJung-uk Kim *****************************************************************************/
1870b94ba42SJung-uk Kim
188d052a1ccSJung-uk Kim ACPI_STATUS
DtResolveIntegerExpression(DT_FIELD * Field,UINT64 * ReturnValue)1890b94ba42SJung-uk Kim DtResolveIntegerExpression (
190d052a1ccSJung-uk Kim DT_FIELD *Field,
191d052a1ccSJung-uk Kim UINT64 *ReturnValue)
1920b94ba42SJung-uk Kim {
193d052a1ccSJung-uk Kim UINT64 Result;
1940b94ba42SJung-uk Kim
1950b94ba42SJung-uk Kim
1960b94ba42SJung-uk Kim DbgPrint (ASL_DEBUG_OUTPUT, "Full Integer expression: %s\n",
1970b94ba42SJung-uk Kim Field->Value);
1980b94ba42SJung-uk Kim
1996f1f1a63SJung-uk Kim AslGbl_CurrentField = Field;
2000b94ba42SJung-uk Kim
201d052a1ccSJung-uk Kim Result = DtEvaluateExpression (Field->Value);
202d052a1ccSJung-uk Kim *ReturnValue = Result;
203d052a1ccSJung-uk Kim return (AE_OK);
2040b94ba42SJung-uk Kim }
2050b94ba42SJung-uk Kim
2060b94ba42SJung-uk Kim
207d052a1ccSJung-uk Kim /******************************************************************************
208d052a1ccSJung-uk Kim *
209d052a1ccSJung-uk Kim * FUNCTION: DtDoOperator
210d052a1ccSJung-uk Kim *
211d052a1ccSJung-uk Kim * PARAMETERS: LeftValue - First 64-bit operand
212ff879b07SJung-uk Kim * Operator - Parse token for the operator (OP_EXP_*)
213d052a1ccSJung-uk Kim * RightValue - Second 64-bit operand
214d052a1ccSJung-uk Kim *
215d052a1ccSJung-uk Kim * RETURN: 64-bit result of the requested operation
216d052a1ccSJung-uk Kim *
217d052a1ccSJung-uk Kim * DESCRIPTION: Perform the various 64-bit integer math functions
218d052a1ccSJung-uk Kim *
219d052a1ccSJung-uk Kim *****************************************************************************/
220d052a1ccSJung-uk Kim
221d052a1ccSJung-uk Kim UINT64
DtDoOperator(UINT64 LeftValue,UINT32 Operator,UINT64 RightValue)222d052a1ccSJung-uk Kim DtDoOperator (
223d052a1ccSJung-uk Kim UINT64 LeftValue,
224d052a1ccSJung-uk Kim UINT32 Operator,
225d052a1ccSJung-uk Kim UINT64 RightValue)
2260b94ba42SJung-uk Kim {
227d052a1ccSJung-uk Kim UINT64 Result;
2280b94ba42SJung-uk Kim
2290b94ba42SJung-uk Kim
2300b94ba42SJung-uk Kim /* Perform the requested operation */
2310b94ba42SJung-uk Kim
232d052a1ccSJung-uk Kim switch (Operator)
2330b94ba42SJung-uk Kim {
234ff879b07SJung-uk Kim case OP_EXP_ONES_COMPLIMENT:
235a9d8d09cSJung-uk Kim
236d052a1ccSJung-uk Kim Result = ~RightValue;
2370b94ba42SJung-uk Kim break;
2380b94ba42SJung-uk Kim
239ff879b07SJung-uk Kim case OP_EXP_LOGICAL_NOT:
240a9d8d09cSJung-uk Kim
241d052a1ccSJung-uk Kim Result = !RightValue;
2420b94ba42SJung-uk Kim break;
2430b94ba42SJung-uk Kim
244ff879b07SJung-uk Kim case OP_EXP_MULTIPLY:
245a9d8d09cSJung-uk Kim
246d052a1ccSJung-uk Kim Result = LeftValue * RightValue;
2470b94ba42SJung-uk Kim break;
2480b94ba42SJung-uk Kim
249ff879b07SJung-uk Kim case OP_EXP_DIVIDE:
250a9d8d09cSJung-uk Kim
251d052a1ccSJung-uk Kim if (!RightValue)
2520b94ba42SJung-uk Kim {
253d052a1ccSJung-uk Kim DtError (ASL_ERROR, ASL_MSG_DIVIDE_BY_ZERO,
2546f1f1a63SJung-uk Kim AslGbl_CurrentField, NULL);
2550b94ba42SJung-uk Kim return (0);
2560b94ba42SJung-uk Kim }
257f8146b88SJung-uk Kim
258d052a1ccSJung-uk Kim Result = LeftValue / RightValue;
2590b94ba42SJung-uk Kim break;
2600b94ba42SJung-uk Kim
261ff879b07SJung-uk Kim case OP_EXP_MODULO:
262a9d8d09cSJung-uk Kim
263d052a1ccSJung-uk Kim if (!RightValue)
2640b94ba42SJung-uk Kim {
265d052a1ccSJung-uk Kim DtError (ASL_ERROR, ASL_MSG_DIVIDE_BY_ZERO,
2666f1f1a63SJung-uk Kim AslGbl_CurrentField, NULL);
2670b94ba42SJung-uk Kim return (0);
2680b94ba42SJung-uk Kim }
269f8146b88SJung-uk Kim
270d052a1ccSJung-uk Kim Result = LeftValue % RightValue;
271d052a1ccSJung-uk Kim break;
272d052a1ccSJung-uk Kim
273ff879b07SJung-uk Kim case OP_EXP_ADD:
274d052a1ccSJung-uk Kim Result = LeftValue + RightValue;
275d052a1ccSJung-uk Kim break;
276d052a1ccSJung-uk Kim
277ff879b07SJung-uk Kim case OP_EXP_SUBTRACT:
278a9d8d09cSJung-uk Kim
279d052a1ccSJung-uk Kim Result = LeftValue - RightValue;
280d052a1ccSJung-uk Kim break;
281d052a1ccSJung-uk Kim
282ff879b07SJung-uk Kim case OP_EXP_SHIFT_RIGHT:
283a9d8d09cSJung-uk Kim
284d052a1ccSJung-uk Kim Result = LeftValue >> RightValue;
285d052a1ccSJung-uk Kim break;
286d052a1ccSJung-uk Kim
287ff879b07SJung-uk Kim case OP_EXP_SHIFT_LEFT:
288a9d8d09cSJung-uk Kim
289d052a1ccSJung-uk Kim Result = LeftValue << RightValue;
290d052a1ccSJung-uk Kim break;
291d052a1ccSJung-uk Kim
292ff879b07SJung-uk Kim case OP_EXP_LESS:
293a9d8d09cSJung-uk Kim
294d052a1ccSJung-uk Kim Result = LeftValue < RightValue;
295d052a1ccSJung-uk Kim break;
296d052a1ccSJung-uk Kim
297ff879b07SJung-uk Kim case OP_EXP_GREATER:
298a9d8d09cSJung-uk Kim
299d052a1ccSJung-uk Kim Result = LeftValue > RightValue;
300d052a1ccSJung-uk Kim break;
301d052a1ccSJung-uk Kim
302ff879b07SJung-uk Kim case OP_EXP_LESS_EQUAL:
303a9d8d09cSJung-uk Kim
304d052a1ccSJung-uk Kim Result = LeftValue <= RightValue;
305d052a1ccSJung-uk Kim break;
306d052a1ccSJung-uk Kim
307ff879b07SJung-uk Kim case OP_EXP_GREATER_EQUAL:
308a9d8d09cSJung-uk Kim
309d052a1ccSJung-uk Kim Result = LeftValue >= RightValue;
310d052a1ccSJung-uk Kim break;
311d052a1ccSJung-uk Kim
312ff879b07SJung-uk Kim case OP_EXP_EQUAL:
313a9d8d09cSJung-uk Kim
3144c52cad2SJung-uk Kim Result = LeftValue == RightValue;
315d052a1ccSJung-uk Kim break;
316d052a1ccSJung-uk Kim
317ff879b07SJung-uk Kim case OP_EXP_NOT_EQUAL:
318a9d8d09cSJung-uk Kim
319d052a1ccSJung-uk Kim Result = LeftValue != RightValue;
320d052a1ccSJung-uk Kim break;
321d052a1ccSJung-uk Kim
322ff879b07SJung-uk Kim case OP_EXP_AND:
323a9d8d09cSJung-uk Kim
324d052a1ccSJung-uk Kim Result = LeftValue & RightValue;
325d052a1ccSJung-uk Kim break;
326d052a1ccSJung-uk Kim
327ff879b07SJung-uk Kim case OP_EXP_XOR:
328a9d8d09cSJung-uk Kim
329d052a1ccSJung-uk Kim Result = LeftValue ^ RightValue;
330d052a1ccSJung-uk Kim break;
331d052a1ccSJung-uk Kim
332ff879b07SJung-uk Kim case OP_EXP_OR:
333a9d8d09cSJung-uk Kim
334d052a1ccSJung-uk Kim Result = LeftValue | RightValue;
335d052a1ccSJung-uk Kim break;
336d052a1ccSJung-uk Kim
337ff879b07SJung-uk Kim case OP_EXP_LOGICAL_AND:
338a9d8d09cSJung-uk Kim
339d052a1ccSJung-uk Kim Result = LeftValue && RightValue;
340d052a1ccSJung-uk Kim break;
341d052a1ccSJung-uk Kim
342ff879b07SJung-uk Kim case OP_EXP_LOGICAL_OR:
343a9d8d09cSJung-uk Kim
344d052a1ccSJung-uk Kim Result = LeftValue || RightValue;
3450b94ba42SJung-uk Kim break;
3460b94ba42SJung-uk Kim
3470b94ba42SJung-uk Kim default:
3480b94ba42SJung-uk Kim
3490b94ba42SJung-uk Kim /* Unknown operator */
3500b94ba42SJung-uk Kim
351d052a1ccSJung-uk Kim DtFatal (ASL_MSG_INVALID_EXPRESSION,
3526f1f1a63SJung-uk Kim AslGbl_CurrentField, NULL);
353d052a1ccSJung-uk Kim return (0);
3540b94ba42SJung-uk Kim }
3550b94ba42SJung-uk Kim
356d052a1ccSJung-uk Kim DbgPrint (ASL_DEBUG_OUTPUT,
3574c52cad2SJung-uk Kim "IntegerEval: (%8.8X%8.8X %s %8.8X%8.8X) = %8.8X%8.8X\n",
358d052a1ccSJung-uk Kim ACPI_FORMAT_UINT64 (LeftValue),
359d052a1ccSJung-uk Kim DtGetOpName (Operator),
360d052a1ccSJung-uk Kim ACPI_FORMAT_UINT64 (RightValue),
361d052a1ccSJung-uk Kim ACPI_FORMAT_UINT64 (Result));
362d052a1ccSJung-uk Kim
363d052a1ccSJung-uk Kim return (Result);
3640b94ba42SJung-uk Kim }
3650b94ba42SJung-uk Kim
3660b94ba42SJung-uk Kim
3670b94ba42SJung-uk Kim /******************************************************************************
3680b94ba42SJung-uk Kim *
369d052a1ccSJung-uk Kim * FUNCTION: DtResolveLabel
3700b94ba42SJung-uk Kim *
371d052a1ccSJung-uk Kim * PARAMETERS: LabelString - Contains the label
3720b94ba42SJung-uk Kim *
373d052a1ccSJung-uk Kim * RETURN: Table offset associated with the label
3740b94ba42SJung-uk Kim *
375cd6518c7SJung-uk Kim * DESCRIPTION: Lookup a label and return its value.
3760b94ba42SJung-uk Kim *
3770b94ba42SJung-uk Kim *****************************************************************************/
3780b94ba42SJung-uk Kim
379d052a1ccSJung-uk Kim UINT64
DtResolveLabel(char * LabelString)380d052a1ccSJung-uk Kim DtResolveLabel (
381d052a1ccSJung-uk Kim char *LabelString)
3820b94ba42SJung-uk Kim {
3830b94ba42SJung-uk Kim DT_FIELD *LabelField;
3840b94ba42SJung-uk Kim
3850b94ba42SJung-uk Kim
386d052a1ccSJung-uk Kim DbgPrint (ASL_DEBUG_OUTPUT, "Resolve Label: %s\n", LabelString);
3870b94ba42SJung-uk Kim
3880b94ba42SJung-uk Kim /* Resolve a label reference to an integer (table offset) */
3890b94ba42SJung-uk Kim
390d052a1ccSJung-uk Kim if (*LabelString != '$')
3910b94ba42SJung-uk Kim {
392d052a1ccSJung-uk Kim return (0);
393d052a1ccSJung-uk Kim }
394d052a1ccSJung-uk Kim
395d052a1ccSJung-uk Kim LabelField = DtLookupLabel (LabelString);
3960b94ba42SJung-uk Kim if (!LabelField)
3970b94ba42SJung-uk Kim {
398d052a1ccSJung-uk Kim DtError (ASL_ERROR, ASL_MSG_UNKNOWN_LABEL,
3996f1f1a63SJung-uk Kim AslGbl_CurrentField, LabelString);
4000b94ba42SJung-uk Kim return (0);
4010b94ba42SJung-uk Kim }
4020b94ba42SJung-uk Kim
4030b94ba42SJung-uk Kim /* All we need from the label is the offset in the table */
4040b94ba42SJung-uk Kim
405d052a1ccSJung-uk Kim DbgPrint (ASL_DEBUG_OUTPUT, "Resolved Label: 0x%8.8X\n",
406d052a1ccSJung-uk Kim LabelField->TableOffset);
4070b94ba42SJung-uk Kim
408d052a1ccSJung-uk Kim return (LabelField->TableOffset);
4090b94ba42SJung-uk Kim }
4100b94ba42SJung-uk Kim
4110b94ba42SJung-uk Kim
4120b94ba42SJung-uk Kim /******************************************************************************
4130b94ba42SJung-uk Kim *
4140b94ba42SJung-uk Kim * FUNCTION: DtDetectAllLabels
4150b94ba42SJung-uk Kim *
4160b94ba42SJung-uk Kim * PARAMETERS: FieldList - Field object at start of generic list
4170b94ba42SJung-uk Kim *
4180b94ba42SJung-uk Kim * RETURN: None
4190b94ba42SJung-uk Kim *
4200b94ba42SJung-uk Kim * DESCRIPTION: Detect all labels in a list of "generic" opcodes (such as
4210b94ba42SJung-uk Kim * a UEFI table.) and insert them into the global label list.
4220b94ba42SJung-uk Kim *
4230b94ba42SJung-uk Kim *****************************************************************************/
4240b94ba42SJung-uk Kim
4250b94ba42SJung-uk Kim void
DtDetectAllLabels(DT_FIELD * FieldList)4260b94ba42SJung-uk Kim DtDetectAllLabels (
4270b94ba42SJung-uk Kim DT_FIELD *FieldList)
4280b94ba42SJung-uk Kim {
4290b94ba42SJung-uk Kim ACPI_DMTABLE_INFO *Info;
4300b94ba42SJung-uk Kim DT_FIELD *GenericField;
4310b94ba42SJung-uk Kim UINT32 TableOffset;
4320b94ba42SJung-uk Kim
4330b94ba42SJung-uk Kim
4346f1f1a63SJung-uk Kim TableOffset = AslGbl_CurrentTableOffset;
4350b94ba42SJung-uk Kim GenericField = FieldList;
4360b94ba42SJung-uk Kim
4370b94ba42SJung-uk Kim /*
4380b94ba42SJung-uk Kim * Process all "Label:" fields within the parse tree. We need
4390b94ba42SJung-uk Kim * to know the offsets for all labels before we can compile
4400b94ba42SJung-uk Kim * the parse tree in order to handle forward references. Traverse
4410b94ba42SJung-uk Kim * tree and get/set all field lengths of all operators in order to
4420b94ba42SJung-uk Kim * determine the label offsets.
4430b94ba42SJung-uk Kim */
4440b94ba42SJung-uk Kim while (GenericField)
4450b94ba42SJung-uk Kim {
4460b94ba42SJung-uk Kim Info = DtGetGenericTableInfo (GenericField->Name);
4470b94ba42SJung-uk Kim if (Info)
4480b94ba42SJung-uk Kim {
4490b94ba42SJung-uk Kim /* Maintain table offsets */
4500b94ba42SJung-uk Kim
4510b94ba42SJung-uk Kim GenericField->TableOffset = TableOffset;
4520b94ba42SJung-uk Kim TableOffset += DtGetFieldLength (GenericField, Info);
4530b94ba42SJung-uk Kim
4540b94ba42SJung-uk Kim /* Insert all labels in the global label list */
4550b94ba42SJung-uk Kim
4560b94ba42SJung-uk Kim if (Info->Opcode == ACPI_DMT_LABEL)
4570b94ba42SJung-uk Kim {
4580b94ba42SJung-uk Kim DtInsertLabelField (GenericField);
4590b94ba42SJung-uk Kim }
4600b94ba42SJung-uk Kim }
4610b94ba42SJung-uk Kim
4620b94ba42SJung-uk Kim GenericField = GenericField->Next;
4630b94ba42SJung-uk Kim }
4640b94ba42SJung-uk Kim }
4650b94ba42SJung-uk Kim
4660b94ba42SJung-uk Kim
4670b94ba42SJung-uk Kim /******************************************************************************
4680b94ba42SJung-uk Kim *
4690b94ba42SJung-uk Kim * FUNCTION: DtInsertLabelField
4700b94ba42SJung-uk Kim *
4710b94ba42SJung-uk Kim * PARAMETERS: Field - Field object with Label to be inserted
4720b94ba42SJung-uk Kim *
4730b94ba42SJung-uk Kim * RETURN: None
4740b94ba42SJung-uk Kim *
4750b94ba42SJung-uk Kim * DESCRIPTION: Insert a label field into the global label list
4760b94ba42SJung-uk Kim *
4770b94ba42SJung-uk Kim *****************************************************************************/
4780b94ba42SJung-uk Kim
4790b94ba42SJung-uk Kim static void
DtInsertLabelField(DT_FIELD * Field)4800b94ba42SJung-uk Kim DtInsertLabelField (
4810b94ba42SJung-uk Kim DT_FIELD *Field)
4820b94ba42SJung-uk Kim {
483722b1667SJung-uk Kim ACPI_FUNCTION_NAME (DtInsertLabelField);
4840b94ba42SJung-uk Kim
4850b94ba42SJung-uk Kim DbgPrint (ASL_DEBUG_OUTPUT,
486722b1667SJung-uk Kim "%s: Found Label : %s at output table offset %X\n",
487722b1667SJung-uk Kim ACPI_GET_FUNCTION_NAME, Field->Value, Field->TableOffset);
4880b94ba42SJung-uk Kim
4896f1f1a63SJung-uk Kim Field->NextLabel = AslGbl_LabelList;
4906f1f1a63SJung-uk Kim AslGbl_LabelList = Field;
4910b94ba42SJung-uk Kim }
4920b94ba42SJung-uk Kim
4930b94ba42SJung-uk Kim
4940b94ba42SJung-uk Kim /******************************************************************************
4950b94ba42SJung-uk Kim *
4960b94ba42SJung-uk Kim * FUNCTION: DtLookupLabel
4970b94ba42SJung-uk Kim *
4980b94ba42SJung-uk Kim * PARAMETERS: Name - Label to be resolved
4990b94ba42SJung-uk Kim *
5000b94ba42SJung-uk Kim * RETURN: Field object associated with the label
5010b94ba42SJung-uk Kim *
5020b94ba42SJung-uk Kim * DESCRIPTION: Lookup a label in the global label list. Used during the
5030b94ba42SJung-uk Kim * resolution of integer expressions.
5040b94ba42SJung-uk Kim *
5050b94ba42SJung-uk Kim *****************************************************************************/
5060b94ba42SJung-uk Kim
5070b94ba42SJung-uk Kim static DT_FIELD *
DtLookupLabel(char * Name)5080b94ba42SJung-uk Kim DtLookupLabel (
5090b94ba42SJung-uk Kim char *Name)
5100b94ba42SJung-uk Kim {
5110b94ba42SJung-uk Kim DT_FIELD *LabelField;
5120b94ba42SJung-uk Kim
5130b94ba42SJung-uk Kim
5140b94ba42SJung-uk Kim /* Skip a leading $ */
5150b94ba42SJung-uk Kim
5160b94ba42SJung-uk Kim if (*Name == '$')
5170b94ba42SJung-uk Kim {
5180b94ba42SJung-uk Kim Name++;
5190b94ba42SJung-uk Kim }
5200b94ba42SJung-uk Kim
5210b94ba42SJung-uk Kim /* Search global list */
5220b94ba42SJung-uk Kim
5236f1f1a63SJung-uk Kim LabelField = AslGbl_LabelList;
5240b94ba42SJung-uk Kim while (LabelField)
5250b94ba42SJung-uk Kim {
5265ef50723SJung-uk Kim if (!strcmp (Name, LabelField->Value))
5270b94ba42SJung-uk Kim {
5280b94ba42SJung-uk Kim return (LabelField);
5290b94ba42SJung-uk Kim }
530f8146b88SJung-uk Kim
5310b94ba42SJung-uk Kim LabelField = LabelField->NextLabel;
5320b94ba42SJung-uk Kim }
5330b94ba42SJung-uk Kim
5340b94ba42SJung-uk Kim return (NULL);
5350b94ba42SJung-uk Kim }
536