1218585Sjkim/******************************************************************************
2218585Sjkim *
3218585Sjkim * Module Name: dtexpress.c - Support for integer expressions and labels
4218585Sjkim *
5218585Sjkim *****************************************************************************/
6218585Sjkim
7316303Sjkim/******************************************************************************
8316303Sjkim *
9316303Sjkim * 1. Copyright Notice
10316303Sjkim *
11316303Sjkim * Some or all of this work - Copyright (c) 1999 - 2017, Intel Corp.
12218585Sjkim * All rights reserved.
13218585Sjkim *
14316303Sjkim * 2. License
15316303Sjkim *
16316303Sjkim * 2.1. This is your license from Intel Corp. under its intellectual property
17316303Sjkim * rights. You may have additional license terms from the party that provided
18316303Sjkim * you this software, covering your right to use that party's intellectual
19316303Sjkim * property rights.
20316303Sjkim *
21316303Sjkim * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
22316303Sjkim * copy of the source code appearing in this file ("Covered Code") an
23316303Sjkim * irrevocable, perpetual, worldwide license under Intel's copyrights in the
24316303Sjkim * base code distributed originally by Intel ("Original Intel Code") to copy,
25316303Sjkim * make derivatives, distribute, use and display any portion of the Covered
26316303Sjkim * Code in any form, with the right to sublicense such rights; and
27316303Sjkim *
28316303Sjkim * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
29316303Sjkim * license (with the right to sublicense), under only those claims of Intel
30316303Sjkim * patents that are infringed by the Original Intel Code, to make, use, sell,
31316303Sjkim * offer to sell, and import the Covered Code and derivative works thereof
32316303Sjkim * solely to the minimum extent necessary to exercise the above copyright
33316303Sjkim * license, and in no event shall the patent license extend to any additions
34316303Sjkim * to or modifications of the Original Intel Code. No other license or right
35316303Sjkim * is granted directly or by implication, estoppel or otherwise;
36316303Sjkim *
37316303Sjkim * The above copyright and patent license is granted only if the following
38316303Sjkim * conditions are met:
39316303Sjkim *
40316303Sjkim * 3. Conditions
41316303Sjkim *
42316303Sjkim * 3.1. Redistribution of Source with Rights to Further Distribute Source.
43316303Sjkim * Redistribution of source code of any substantial portion of the Covered
44316303Sjkim * Code or modification with rights to further distribute source must include
45316303Sjkim * the above Copyright Notice, the above License, this list of Conditions,
46316303Sjkim * and the following Disclaimer and Export Compliance provision. In addition,
47316303Sjkim * Licensee must cause all Covered Code to which Licensee contributes to
48316303Sjkim * contain a file documenting the changes Licensee made to create that Covered
49316303Sjkim * Code and the date of any change. Licensee must include in that file the
50316303Sjkim * documentation of any changes made by any predecessor Licensee. Licensee
51316303Sjkim * must include a prominent statement that the modification is derived,
52316303Sjkim * directly or indirectly, from Original Intel Code.
53316303Sjkim *
54316303Sjkim * 3.2. Redistribution of Source with no Rights to Further Distribute Source.
55316303Sjkim * Redistribution of source code of any substantial portion of the Covered
56316303Sjkim * Code or modification without rights to further distribute source must
57316303Sjkim * include the following Disclaimer and Export Compliance provision in the
58316303Sjkim * documentation and/or other materials provided with distribution. In
59316303Sjkim * addition, Licensee may not authorize further sublicense of source of any
60316303Sjkim * portion of the Covered Code, and must include terms to the effect that the
61316303Sjkim * license from Licensee to its licensee is limited to the intellectual
62316303Sjkim * property embodied in the software Licensee provides to its licensee, and
63316303Sjkim * not to intellectual property embodied in modifications its licensee may
64316303Sjkim * make.
65316303Sjkim *
66316303Sjkim * 3.3. Redistribution of Executable. Redistribution in executable form of any
67316303Sjkim * substantial portion of the Covered Code or modification must reproduce the
68316303Sjkim * above Copyright Notice, and the following Disclaimer and Export Compliance
69316303Sjkim * provision in the documentation and/or other materials provided with the
70316303Sjkim * distribution.
71316303Sjkim *
72316303Sjkim * 3.4. Intel retains all right, title, and interest in and to the Original
73316303Sjkim * Intel Code.
74316303Sjkim *
75316303Sjkim * 3.5. Neither the name Intel nor any other trademark owned or controlled by
76316303Sjkim * Intel shall be used in advertising or otherwise to promote the sale, use or
77316303Sjkim * other dealings in products derived from or relating to the Covered Code
78316303Sjkim * without prior written authorization from Intel.
79316303Sjkim *
80316303Sjkim * 4. Disclaimer and Export Compliance
81316303Sjkim *
82316303Sjkim * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
83316303Sjkim * HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
84316303Sjkim * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE,
85316303Sjkim * INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY
86316303Sjkim * UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY
87316303Sjkim * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
88316303Sjkim * PARTICULAR PURPOSE.
89316303Sjkim *
90316303Sjkim * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
91316303Sjkim * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
92316303Sjkim * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
93316303Sjkim * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
94316303Sjkim * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
95316303Sjkim * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS
96316303Sjkim * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
97316303Sjkim * LIMITED REMEDY.
98316303Sjkim *
99316303Sjkim * 4.3. Licensee shall not export, either directly or indirectly, any of this
100316303Sjkim * software or system incorporating such software without first obtaining any
101316303Sjkim * required license or other approval from the U. S. Department of Commerce or
102316303Sjkim * any other agency or department of the United States Government. In the
103316303Sjkim * event Licensee exports any such software from the United States or
104316303Sjkim * re-exports any such software from a foreign destination, Licensee shall
105316303Sjkim * ensure that the distribution and export/re-export of the software is in
106316303Sjkim * compliance with all laws, regulations, orders, or other restrictions of the
107316303Sjkim * U.S. Export Administration Regulations. Licensee agrees that neither it nor
108316303Sjkim * any of its subsidiaries will export/re-export any technical data, process,
109316303Sjkim * software, or service, directly or indirectly, to any country for which the
110316303Sjkim * United States government or any agency thereof requires an export license,
111316303Sjkim * other governmental approval, or letter of assurance, without first obtaining
112316303Sjkim * such license, approval or letter.
113316303Sjkim *
114316303Sjkim *****************************************************************************
115316303Sjkim *
116316303Sjkim * Alternatively, you may choose to be licensed under the terms of the
117316303Sjkim * following license:
118316303Sjkim *
119218585Sjkim * Redistribution and use in source and binary forms, with or without
120218585Sjkim * modification, are permitted provided that the following conditions
121218585Sjkim * are met:
122218585Sjkim * 1. Redistributions of source code must retain the above copyright
123218585Sjkim *    notice, this list of conditions, and the following disclaimer,
124218585Sjkim *    without modification.
125218585Sjkim * 2. Redistributions in binary form must reproduce at minimum a disclaimer
126218585Sjkim *    substantially similar to the "NO WARRANTY" disclaimer below
127218585Sjkim *    ("Disclaimer") and any redistribution must be conditioned upon
128218585Sjkim *    including a substantially similar Disclaimer requirement for further
129218585Sjkim *    binary redistribution.
130218585Sjkim * 3. Neither the names of the above-listed copyright holders nor the names
131218585Sjkim *    of any contributors may be used to endorse or promote products derived
132218585Sjkim *    from this software without specific prior written permission.
133218585Sjkim *
134316303Sjkim * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
135316303Sjkim * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
136316303Sjkim * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
137316303Sjkim * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
138316303Sjkim * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
139316303Sjkim * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
140316303Sjkim * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
141316303Sjkim * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
142316303Sjkim * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
143316303Sjkim * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
144316303Sjkim * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
145316303Sjkim *
146316303Sjkim * Alternatively, you may choose to be licensed under the terms of the
147218585Sjkim * GNU General Public License ("GPL") version 2 as published by the Free
148218585Sjkim * Software Foundation.
149218585Sjkim *
150316303Sjkim *****************************************************************************/
151218585Sjkim
152218590Sjkim#include <contrib/dev/acpica/compiler/aslcompiler.h>
153220663Sjkim#include "dtparser.y.h"
154218585Sjkim
155218585Sjkim#define _COMPONENT          DT_COMPILER
156218585Sjkim        ACPI_MODULE_NAME    ("dtexpress")
157218585Sjkim
158218585Sjkim
159218585Sjkim/* Local prototypes */
160218585Sjkim
161218585Sjkimstatic void
162218585SjkimDtInsertLabelField (
163218585Sjkim    DT_FIELD                *Field);
164218585Sjkim
165218585Sjkimstatic DT_FIELD *
166218585SjkimDtLookupLabel (
167218585Sjkim    char                    *Name);
168218585Sjkim
169220663Sjkim/* Global used for errors during parse and related functions */
170218585Sjkim
171220663SjkimDT_FIELD                *Gbl_CurrentField;
172220663Sjkim
173220663Sjkim
174218585Sjkim/******************************************************************************
175218585Sjkim *
176218585Sjkim * FUNCTION:    DtResolveIntegerExpression
177218585Sjkim *
178218585Sjkim * PARAMETERS:  Field               - Field object with Integer expression
179220663Sjkim *              ReturnValue         - Where the integer is returned
180218585Sjkim *
181220663Sjkim * RETURN:      Status, and the resolved 64-bit integer value
182218585Sjkim *
183218585Sjkim * DESCRIPTION: Resolve an integer expression to a single value. Supports
184220663Sjkim *              both integer constants and labels.
185218585Sjkim *
186218585Sjkim *****************************************************************************/
187218585Sjkim
188220663SjkimACPI_STATUS
189218585SjkimDtResolveIntegerExpression (
190220663Sjkim    DT_FIELD                *Field,
191220663Sjkim    UINT64                  *ReturnValue)
192218585Sjkim{
193220663Sjkim    UINT64                  Result;
194218585Sjkim
195218585Sjkim
196218585Sjkim    DbgPrint (ASL_DEBUG_OUTPUT, "Full Integer expression: %s\n",
197218585Sjkim        Field->Value);
198218585Sjkim
199220663Sjkim    Gbl_CurrentField = Field;
200218585Sjkim
201220663Sjkim    Result = DtEvaluateExpression (Field->Value);
202220663Sjkim    *ReturnValue = Result;
203220663Sjkim    return (AE_OK);
204220663Sjkim}
205218585Sjkim
206218585Sjkim
207220663Sjkim/******************************************************************************
208220663Sjkim *
209220663Sjkim * FUNCTION:    DtDoOperator
210220663Sjkim *
211220663Sjkim * PARAMETERS:  LeftValue           - First 64-bit operand
212220663Sjkim *              Operator            - Parse token for the operator (EXPOP_*)
213220663Sjkim *              RightValue          - Second 64-bit operand
214220663Sjkim *
215220663Sjkim * RETURN:      64-bit result of the requested operation
216220663Sjkim *
217220663Sjkim * DESCRIPTION: Perform the various 64-bit integer math functions
218220663Sjkim *
219220663Sjkim *****************************************************************************/
220218585Sjkim
221220663SjkimUINT64
222220663SjkimDtDoOperator (
223220663Sjkim    UINT64                  LeftValue,
224220663Sjkim    UINT32                  Operator,
225220663Sjkim    UINT64                  RightValue)
226220663Sjkim{
227220663Sjkim    UINT64                  Result;
228220663Sjkim
229220663Sjkim
230220663Sjkim    /* Perform the requested operation */
231220663Sjkim
232220663Sjkim    switch (Operator)
233218585Sjkim    {
234220663Sjkim    case EXPOP_ONES_COMPLIMENT:
235250838Sjkim
236220663Sjkim        Result = ~RightValue;
237220663Sjkim        break;
238218585Sjkim
239220663Sjkim    case EXPOP_LOGICAL_NOT:
240250838Sjkim
241220663Sjkim        Result = !RightValue;
242220663Sjkim        break;
243218585Sjkim
244220663Sjkim    case EXPOP_MULTIPLY:
245250838Sjkim
246220663Sjkim        Result = LeftValue * RightValue;
247220663Sjkim        break;
248220663Sjkim
249220663Sjkim    case EXPOP_DIVIDE:
250250838Sjkim
251220663Sjkim        if (!RightValue)
252220663Sjkim        {
253220663Sjkim            DtError (ASL_ERROR, ASL_MSG_DIVIDE_BY_ZERO,
254233250Sjkim                Gbl_CurrentField, NULL);
255220663Sjkim            return (0);
256218585Sjkim        }
257298714Sjkim
258220663Sjkim        Result = LeftValue / RightValue;
259220663Sjkim        break;
260218585Sjkim
261220663Sjkim    case EXPOP_MODULO:
262250838Sjkim
263220663Sjkim        if (!RightValue)
264218585Sjkim        {
265220663Sjkim            DtError (ASL_ERROR, ASL_MSG_DIVIDE_BY_ZERO,
266233250Sjkim                Gbl_CurrentField, NULL);
267218585Sjkim            return (0);
268218585Sjkim        }
269298714Sjkim
270220663Sjkim        Result = LeftValue % RightValue;
271220663Sjkim        break;
272218585Sjkim
273220663Sjkim    case EXPOP_ADD:
274220663Sjkim        Result = LeftValue + RightValue;
275220663Sjkim        break;
276218585Sjkim
277220663Sjkim    case EXPOP_SUBTRACT:
278250838Sjkim
279220663Sjkim        Result = LeftValue - RightValue;
280220663Sjkim        break;
281218585Sjkim
282220663Sjkim    case EXPOP_SHIFT_RIGHT:
283250838Sjkim
284220663Sjkim        Result = LeftValue >> RightValue;
285220663Sjkim        break;
286218585Sjkim
287220663Sjkim    case EXPOP_SHIFT_LEFT:
288250838Sjkim
289220663Sjkim        Result = LeftValue << RightValue;
290220663Sjkim        break;
291218585Sjkim
292220663Sjkim    case EXPOP_LESS:
293250838Sjkim
294220663Sjkim        Result = LeftValue < RightValue;
295220663Sjkim        break;
296218585Sjkim
297220663Sjkim    case EXPOP_GREATER:
298250838Sjkim
299220663Sjkim        Result = LeftValue > RightValue;
300220663Sjkim        break;
301218585Sjkim
302220663Sjkim    case EXPOP_LESS_EQUAL:
303250838Sjkim
304220663Sjkim        Result = LeftValue <= RightValue;
305220663Sjkim        break;
306218585Sjkim
307220663Sjkim    case EXPOP_GREATER_EQUAL:
308250838Sjkim
309220663Sjkim        Result = LeftValue >= RightValue;
310220663Sjkim        break;
311218585Sjkim
312220663Sjkim    case EXPOP_EQUAL:
313250838Sjkim
314233250Sjkim        Result = LeftValue == RightValue;
315220663Sjkim        break;
316218585Sjkim
317220663Sjkim    case EXPOP_NOT_EQUAL:
318250838Sjkim
319220663Sjkim        Result = LeftValue != RightValue;
320220663Sjkim        break;
321218585Sjkim
322220663Sjkim    case EXPOP_AND:
323250838Sjkim
324220663Sjkim        Result = LeftValue & RightValue;
325220663Sjkim        break;
326218585Sjkim
327220663Sjkim    case EXPOP_XOR:
328250838Sjkim
329220663Sjkim        Result = LeftValue ^ RightValue;
330220663Sjkim        break;
331218585Sjkim
332220663Sjkim    case EXPOP_OR:
333250838Sjkim
334220663Sjkim        Result = LeftValue | RightValue;
335220663Sjkim        break;
336220663Sjkim
337220663Sjkim    case EXPOP_LOGICAL_AND:
338250838Sjkim
339220663Sjkim        Result = LeftValue && RightValue;
340220663Sjkim        break;
341220663Sjkim
342220663Sjkim    case EXPOP_LOGICAL_OR:
343250838Sjkim
344220663Sjkim        Result = LeftValue || RightValue;
345220663Sjkim        break;
346220663Sjkim
347220663Sjkim   default:
348220663Sjkim
349220663Sjkim        /* Unknown operator */
350220663Sjkim
351220663Sjkim        DtFatal (ASL_MSG_INVALID_EXPRESSION,
352233250Sjkim            Gbl_CurrentField, NULL);
353220663Sjkim        return (0);
354218585Sjkim    }
355218585Sjkim
356220663Sjkim    DbgPrint (ASL_DEBUG_OUTPUT,
357233250Sjkim        "IntegerEval: (%8.8X%8.8X %s %8.8X%8.8X) = %8.8X%8.8X\n",
358220663Sjkim        ACPI_FORMAT_UINT64 (LeftValue),
359220663Sjkim        DtGetOpName (Operator),
360220663Sjkim        ACPI_FORMAT_UINT64 (RightValue),
361220663Sjkim        ACPI_FORMAT_UINT64 (Result));
362220663Sjkim
363220663Sjkim    return (Result);
364218585Sjkim}
365218585Sjkim
366218585Sjkim
367218585Sjkim/******************************************************************************
368218585Sjkim *
369220663Sjkim * FUNCTION:    DtResolveLabel
370218585Sjkim *
371220663Sjkim * PARAMETERS:  LabelString         - Contains the label
372218585Sjkim *
373220663Sjkim * RETURN:      Table offset associated with the label
374218585Sjkim *
375220663Sjkim * DESCRIPTION: Lookup a lable and return its value.
376218585Sjkim *
377218585Sjkim *****************************************************************************/
378218585Sjkim
379220663SjkimUINT64
380220663SjkimDtResolveLabel (
381220663Sjkim    char                    *LabelString)
382218585Sjkim{
383218585Sjkim    DT_FIELD                *LabelField;
384218585Sjkim
385218585Sjkim
386220663Sjkim    DbgPrint (ASL_DEBUG_OUTPUT, "Resolve Label: %s\n", LabelString);
387218585Sjkim
388218585Sjkim    /* Resolve a label reference to an integer (table offset) */
389218585Sjkim
390220663Sjkim    if (*LabelString != '$')
391218585Sjkim    {
392220663Sjkim        return (0);
393220663Sjkim    }
394218585Sjkim
395220663Sjkim    LabelField = DtLookupLabel (LabelString);
396220663Sjkim    if (!LabelField)
397220663Sjkim    {
398220663Sjkim        DtError (ASL_ERROR, ASL_MSG_UNKNOWN_LABEL,
399220663Sjkim            Gbl_CurrentField, LabelString);
400220663Sjkim        return (0);
401218585Sjkim    }
402218585Sjkim
403220663Sjkim    /* All we need from the label is the offset in the table */
404218585Sjkim
405220663Sjkim    DbgPrint (ASL_DEBUG_OUTPUT, "Resolved Label: 0x%8.8X\n",
406220663Sjkim        LabelField->TableOffset);
407218585Sjkim
408220663Sjkim    return (LabelField->TableOffset);
409218585Sjkim}
410218585Sjkim
411218585Sjkim
412218585Sjkim/******************************************************************************
413218585Sjkim *
414218585Sjkim * FUNCTION:    DtDetectAllLabels
415218585Sjkim *
416218585Sjkim * PARAMETERS:  FieldList           - Field object at start of generic list
417218585Sjkim *
418218585Sjkim * RETURN:      None
419218585Sjkim *
420218585Sjkim * DESCRIPTION: Detect all labels in a list of "generic" opcodes (such as
421218585Sjkim *              a UEFI table.) and insert them into the global label list.
422218585Sjkim *
423218585Sjkim *****************************************************************************/
424218585Sjkim
425218585Sjkimvoid
426218585SjkimDtDetectAllLabels (
427218585Sjkim    DT_FIELD                *FieldList)
428218585Sjkim{
429218585Sjkim    ACPI_DMTABLE_INFO       *Info;
430218585Sjkim    DT_FIELD                *GenericField;
431218585Sjkim    UINT32                  TableOffset;
432218585Sjkim
433218585Sjkim
434218585Sjkim    TableOffset = Gbl_CurrentTableOffset;
435218585Sjkim    GenericField = FieldList;
436218585Sjkim
437218585Sjkim    /*
438218585Sjkim     * Process all "Label:" fields within the parse tree. We need
439218585Sjkim     * to know the offsets for all labels before we can compile
440218585Sjkim     * the parse tree in order to handle forward references. Traverse
441218585Sjkim     * tree and get/set all field lengths of all operators in order to
442218585Sjkim     * determine the label offsets.
443218585Sjkim     */
444218585Sjkim    while (GenericField)
445218585Sjkim    {
446218585Sjkim        Info = DtGetGenericTableInfo (GenericField->Name);
447218585Sjkim        if (Info)
448218585Sjkim        {
449218585Sjkim            /* Maintain table offsets */
450218585Sjkim
451218585Sjkim            GenericField->TableOffset = TableOffset;
452218585Sjkim            TableOffset += DtGetFieldLength (GenericField, Info);
453218585Sjkim
454218585Sjkim            /* Insert all labels in the global label list */
455218585Sjkim
456218585Sjkim            if (Info->Opcode == ACPI_DMT_LABEL)
457218585Sjkim            {
458218585Sjkim                DtInsertLabelField (GenericField);
459218585Sjkim            }
460218585Sjkim        }
461218585Sjkim
462218585Sjkim        GenericField = GenericField->Next;
463218585Sjkim    }
464218585Sjkim}
465218585Sjkim
466218585Sjkim
467218585Sjkim/******************************************************************************
468218585Sjkim *
469218585Sjkim * FUNCTION:    DtInsertLabelField
470218585Sjkim *
471218585Sjkim * PARAMETERS:  Field               - Field object with Label to be inserted
472218585Sjkim *
473218585Sjkim * RETURN:      None
474218585Sjkim *
475218585Sjkim * DESCRIPTION: Insert a label field into the global label list
476218585Sjkim *
477218585Sjkim *****************************************************************************/
478218585Sjkim
479218585Sjkimstatic void
480218585SjkimDtInsertLabelField (
481218585Sjkim    DT_FIELD                *Field)
482218585Sjkim{
483218585Sjkim
484218585Sjkim    DbgPrint (ASL_DEBUG_OUTPUT,
485218585Sjkim        "DtInsertLabelField: Found Label : %s at output table offset %X\n",
486218585Sjkim        Field->Value, Field->TableOffset);
487218585Sjkim
488218585Sjkim    Field->NextLabel = Gbl_LabelList;
489218585Sjkim    Gbl_LabelList = Field;
490218585Sjkim}
491218585Sjkim
492218585Sjkim
493218585Sjkim/******************************************************************************
494218585Sjkim *
495218585Sjkim * FUNCTION:    DtLookupLabel
496218585Sjkim *
497218585Sjkim * PARAMETERS:  Name                - Label to be resolved
498218585Sjkim *
499218585Sjkim * RETURN:      Field object associated with the label
500218585Sjkim *
501218585Sjkim * DESCRIPTION: Lookup a label in the global label list. Used during the
502218585Sjkim *              resolution of integer expressions.
503218585Sjkim *
504218585Sjkim *****************************************************************************/
505218585Sjkim
506218585Sjkimstatic DT_FIELD *
507218585SjkimDtLookupLabel (
508218585Sjkim    char                    *Name)
509218585Sjkim{
510218585Sjkim    DT_FIELD                *LabelField;
511218585Sjkim
512218585Sjkim
513218585Sjkim    /* Skip a leading $ */
514218585Sjkim
515218585Sjkim    if (*Name == '$')
516218585Sjkim    {
517218585Sjkim        Name++;
518218585Sjkim    }
519218585Sjkim
520218585Sjkim    /* Search global list */
521218585Sjkim
522218585Sjkim    LabelField = Gbl_LabelList;
523218585Sjkim    while (LabelField)
524218585Sjkim    {
525284583Sjkim        if (!strcmp (Name, LabelField->Value))
526218585Sjkim        {
527218585Sjkim            return (LabelField);
528218585Sjkim        }
529298714Sjkim
530218585Sjkim        LabelField = LabelField->NextLabel;
531218585Sjkim    }
532218585Sjkim
533218585Sjkim    return (NULL);
534218585Sjkim}
535