1220604Sjkim%{ 2220604Sjkim/****************************************************************************** 3220604Sjkim * 4220604Sjkim * Module Name: dtparser.y - Bison input file for table compiler parser 5220604Sjkim * 6220604Sjkim *****************************************************************************/ 7220604Sjkim 8316303Sjkim/****************************************************************************** 9316303Sjkim * 10316303Sjkim * 1. Copyright Notice 11316303Sjkim * 12316303Sjkim * Some or all of this work - Copyright (c) 1999 - 2017, Intel Corp. 13220604Sjkim * All rights reserved. 14220604Sjkim * 15316303Sjkim * 2. License 16316303Sjkim * 17316303Sjkim * 2.1. This is your license from Intel Corp. under its intellectual property 18316303Sjkim * rights. You may have additional license terms from the party that provided 19316303Sjkim * you this software, covering your right to use that party's intellectual 20316303Sjkim * property rights. 21316303Sjkim * 22316303Sjkim * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a 23316303Sjkim * copy of the source code appearing in this file ("Covered Code") an 24316303Sjkim * irrevocable, perpetual, worldwide license under Intel's copyrights in the 25316303Sjkim * base code distributed originally by Intel ("Original Intel Code") to copy, 26316303Sjkim * make derivatives, distribute, use and display any portion of the Covered 27316303Sjkim * Code in any form, with the right to sublicense such rights; and 28316303Sjkim * 29316303Sjkim * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent 30316303Sjkim * license (with the right to sublicense), under only those claims of Intel 31316303Sjkim * patents that are infringed by the Original Intel Code, to make, use, sell, 32316303Sjkim * offer to sell, and import the Covered Code and derivative works thereof 33316303Sjkim * solely to the minimum extent necessary to exercise the above copyright 34316303Sjkim * license, and in no event shall the patent license extend to any additions 35316303Sjkim * to or modifications of the Original Intel Code. No other license or right 36316303Sjkim * is granted directly or by implication, estoppel or otherwise; 37316303Sjkim * 38316303Sjkim * The above copyright and patent license is granted only if the following 39316303Sjkim * conditions are met: 40316303Sjkim * 41316303Sjkim * 3. Conditions 42316303Sjkim * 43316303Sjkim * 3.1. Redistribution of Source with Rights to Further Distribute Source. 44316303Sjkim * Redistribution of source code of any substantial portion of the Covered 45316303Sjkim * Code or modification with rights to further distribute source must include 46316303Sjkim * the above Copyright Notice, the above License, this list of Conditions, 47316303Sjkim * and the following Disclaimer and Export Compliance provision. In addition, 48316303Sjkim * Licensee must cause all Covered Code to which Licensee contributes to 49316303Sjkim * contain a file documenting the changes Licensee made to create that Covered 50316303Sjkim * Code and the date of any change. Licensee must include in that file the 51316303Sjkim * documentation of any changes made by any predecessor Licensee. Licensee 52316303Sjkim * must include a prominent statement that the modification is derived, 53316303Sjkim * directly or indirectly, from Original Intel Code. 54316303Sjkim * 55316303Sjkim * 3.2. Redistribution of Source with no Rights to Further Distribute Source. 56316303Sjkim * Redistribution of source code of any substantial portion of the Covered 57316303Sjkim * Code or modification without rights to further distribute source must 58316303Sjkim * include the following Disclaimer and Export Compliance provision in the 59316303Sjkim * documentation and/or other materials provided with distribution. In 60316303Sjkim * addition, Licensee may not authorize further sublicense of source of any 61316303Sjkim * portion of the Covered Code, and must include terms to the effect that the 62316303Sjkim * license from Licensee to its licensee is limited to the intellectual 63316303Sjkim * property embodied in the software Licensee provides to its licensee, and 64316303Sjkim * not to intellectual property embodied in modifications its licensee may 65316303Sjkim * make. 66316303Sjkim * 67316303Sjkim * 3.3. Redistribution of Executable. Redistribution in executable form of any 68316303Sjkim * substantial portion of the Covered Code or modification must reproduce the 69316303Sjkim * above Copyright Notice, and the following Disclaimer and Export Compliance 70316303Sjkim * provision in the documentation and/or other materials provided with the 71316303Sjkim * distribution. 72316303Sjkim * 73316303Sjkim * 3.4. Intel retains all right, title, and interest in and to the Original 74316303Sjkim * Intel Code. 75316303Sjkim * 76316303Sjkim * 3.5. Neither the name Intel nor any other trademark owned or controlled by 77316303Sjkim * Intel shall be used in advertising or otherwise to promote the sale, use or 78316303Sjkim * other dealings in products derived from or relating to the Covered Code 79316303Sjkim * without prior written authorization from Intel. 80316303Sjkim * 81316303Sjkim * 4. Disclaimer and Export Compliance 82316303Sjkim * 83316303Sjkim * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED 84316303Sjkim * HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE 85316303Sjkim * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE, 86316303Sjkim * INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY 87316303Sjkim * UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY 88316303Sjkim * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A 89316303Sjkim * PARTICULAR PURPOSE. 90316303Sjkim * 91316303Sjkim * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES 92316303Sjkim * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR 93316303Sjkim * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT, 94316303Sjkim * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY 95316303Sjkim * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL 96316303Sjkim * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS 97316303Sjkim * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY 98316303Sjkim * LIMITED REMEDY. 99316303Sjkim * 100316303Sjkim * 4.3. Licensee shall not export, either directly or indirectly, any of this 101316303Sjkim * software or system incorporating such software without first obtaining any 102316303Sjkim * required license or other approval from the U. S. Department of Commerce or 103316303Sjkim * any other agency or department of the United States Government. In the 104316303Sjkim * event Licensee exports any such software from the United States or 105316303Sjkim * re-exports any such software from a foreign destination, Licensee shall 106316303Sjkim * ensure that the distribution and export/re-export of the software is in 107316303Sjkim * compliance with all laws, regulations, orders, or other restrictions of the 108316303Sjkim * U.S. Export Administration Regulations. Licensee agrees that neither it nor 109316303Sjkim * any of its subsidiaries will export/re-export any technical data, process, 110316303Sjkim * software, or service, directly or indirectly, to any country for which the 111316303Sjkim * United States government or any agency thereof requires an export license, 112316303Sjkim * other governmental approval, or letter of assurance, without first obtaining 113316303Sjkim * such license, approval or letter. 114316303Sjkim * 115316303Sjkim ***************************************************************************** 116316303Sjkim * 117316303Sjkim * Alternatively, you may choose to be licensed under the terms of the 118316303Sjkim * following license: 119316303Sjkim * 120220604Sjkim * Redistribution and use in source and binary forms, with or without 121220604Sjkim * modification, are permitted provided that the following conditions 122220604Sjkim * are met: 123220604Sjkim * 1. Redistributions of source code must retain the above copyright 124220604Sjkim * notice, this list of conditions, and the following disclaimer, 125220604Sjkim * without modification. 126220604Sjkim * 2. Redistributions in binary form must reproduce at minimum a disclaimer 127220604Sjkim * substantially similar to the "NO WARRANTY" disclaimer below 128220604Sjkim * ("Disclaimer") and any redistribution must be conditioned upon 129220604Sjkim * including a substantially similar Disclaimer requirement for further 130220604Sjkim * binary redistribution. 131220604Sjkim * 3. Neither the names of the above-listed copyright holders nor the names 132220604Sjkim * of any contributors may be used to endorse or promote products derived 133220604Sjkim * from this software without specific prior written permission. 134220604Sjkim * 135316303Sjkim * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 136316303Sjkim * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 137316303Sjkim * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 138316303Sjkim * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 139316303Sjkim * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 140316303Sjkim * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 141316303Sjkim * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 142316303Sjkim * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 143316303Sjkim * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 144316303Sjkim * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 145316303Sjkim * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 146316303Sjkim * 147316303Sjkim * Alternatively, you may choose to be licensed under the terms of the 148220604Sjkim * GNU General Public License ("GPL") version 2 as published by the Free 149220604Sjkim * Software Foundation. 150220604Sjkim * 151316303Sjkim *****************************************************************************/ 152220604Sjkim 153220663Sjkim#include <contrib/dev/acpica/compiler/aslcompiler.h> 154220604Sjkim 155220681Sjkim#define _COMPONENT DT_COMPILER 156220604Sjkim ACPI_MODULE_NAME ("dtparser") 157220604Sjkim 158284583Sjkimvoid * AslLocalAllocate (unsigned int Size); 159284583Sjkim 160284583Sjkim/* Bison/yacc configuration */ 161284583Sjkim 162284583Sjkim#undef alloca 163284583Sjkim#define alloca AslLocalAllocate 164284583Sjkim 165220681Sjkimint DtParserlex (void); 166220681Sjkimint DtParserparse (void); 167220681Sjkimvoid DtParsererror (char const *msg); 168220681Sjkimextern char *DtParsertext; 169220681Sjkimextern DT_FIELD *Gbl_CurrentField; 170220604Sjkim 171220681SjkimUINT64 DtParserResult; /* Expression return value */ 172220604Sjkim 173220681Sjkim/* Bison/yacc configuration */ 174220681Sjkim 175220681Sjkim#define yytname DtParsername 176220681Sjkim#define YYDEBUG 1 /* Enable debug output */ 177220681Sjkim#define YYERROR_VERBOSE 1 /* Verbose error messages */ 178220681Sjkim#define YYFLAG -32768 179220681Sjkim 180233250Sjkim/* Define YYMALLOC/YYFREE to prevent redefinition errors */ 181233250Sjkim 182233250Sjkim#define YYMALLOC malloc 183233250Sjkim#define YYFREE free 184220604Sjkim%} 185220604Sjkim 186220604Sjkim%union 187220604Sjkim{ 188220604Sjkim UINT64 value; 189220604Sjkim UINT32 op; 190220604Sjkim} 191220604Sjkim 192220681Sjkim/*! [Begin] no source code translation */ 193220681Sjkim 194220604Sjkim%type <value> Expression 195220604Sjkim 196220604Sjkim%token <op> EXPOP_EOF 197220604Sjkim%token <op> EXPOP_NEW_LINE 198220604Sjkim%token <op> EXPOP_NUMBER 199220604Sjkim%token <op> EXPOP_HEX_NUMBER 200220604Sjkim%token <op> EXPOP_DECIMAL_NUMBER 201220604Sjkim%token <op> EXPOP_LABEL 202220604Sjkim%token <op> EXPOP_PAREN_OPEN 203220604Sjkim%token <op> EXPOP_PAREN_CLOSE 204220604Sjkim 205220604Sjkim%left <op> EXPOP_LOGICAL_OR 206220604Sjkim%left <op> EXPOP_LOGICAL_AND 207220604Sjkim%left <op> EXPOP_OR 208220604Sjkim%left <op> EXPOP_XOR 209220604Sjkim%left <op> EXPOP_AND 210220604Sjkim%left <op> EXPOP_EQUAL EXPOP_NOT_EQUAL 211220604Sjkim%left <op> EXPOP_GREATER EXPOP_LESS EXPOP_GREATER_EQUAL EXPOP_LESS_EQUAL 212220604Sjkim%left <op> EXPOP_SHIFT_RIGHT EXPOP_SHIFT_LEFT 213220604Sjkim%left <op> EXPOP_ADD EXPOP_SUBTRACT 214220604Sjkim%left <op> EXPOP_MULTIPLY EXPOP_DIVIDE EXPOP_MODULO 215220604Sjkim%right <op> EXPOP_ONES_COMPLIMENT EXPOP_LOGICAL_NOT 216220604Sjkim 217220604Sjkim%% 218220604Sjkim 219220604Sjkim/* 220220604Sjkim * Operator precedence rules (from K&R) 221220604Sjkim * 222220604Sjkim * 1) ( ) 223220604Sjkim * 2) ! ~ (unary operators that are supported here) 224220604Sjkim * 3) * / % 225220604Sjkim * 4) + - 226220604Sjkim * 5) >> << 227220604Sjkim * 6) < > <= >= 228220604Sjkim * 7) == != 229220604Sjkim * 8) & 230220604Sjkim * 9) ^ 231220604Sjkim * 10) | 232220604Sjkim * 11) && 233220604Sjkim * 12) || 234220604Sjkim */ 235220604SjkimValue 236220604Sjkim : Expression EXPOP_NEW_LINE { DtParserResult=$1; return 0; } /* End of line (newline) */ 237220604Sjkim | Expression EXPOP_EOF { DtParserResult=$1; return 0; } /* End of string (0) */ 238220604Sjkim ; 239220604Sjkim 240220604SjkimExpression 241220604Sjkim 242220604Sjkim /* Unary operators */ 243220604Sjkim 244220604Sjkim : EXPOP_LOGICAL_NOT Expression { $$ = DtDoOperator ($2, EXPOP_LOGICAL_NOT, $2);} 245220604Sjkim | EXPOP_ONES_COMPLIMENT Expression { $$ = DtDoOperator ($2, EXPOP_ONES_COMPLIMENT, $2);} 246220604Sjkim 247220604Sjkim /* Binary operators */ 248220604Sjkim 249220604Sjkim | Expression EXPOP_MULTIPLY Expression { $$ = DtDoOperator ($1, EXPOP_MULTIPLY, $3);} 250220604Sjkim | Expression EXPOP_DIVIDE Expression { $$ = DtDoOperator ($1, EXPOP_DIVIDE, $3);} 251220604Sjkim | Expression EXPOP_MODULO Expression { $$ = DtDoOperator ($1, EXPOP_MODULO, $3);} 252220604Sjkim | Expression EXPOP_ADD Expression { $$ = DtDoOperator ($1, EXPOP_ADD, $3);} 253220604Sjkim | Expression EXPOP_SUBTRACT Expression { $$ = DtDoOperator ($1, EXPOP_SUBTRACT, $3);} 254220604Sjkim | Expression EXPOP_SHIFT_RIGHT Expression { $$ = DtDoOperator ($1, EXPOP_SHIFT_RIGHT, $3);} 255220604Sjkim | Expression EXPOP_SHIFT_LEFT Expression { $$ = DtDoOperator ($1, EXPOP_SHIFT_LEFT, $3);} 256220604Sjkim | Expression EXPOP_GREATER Expression { $$ = DtDoOperator ($1, EXPOP_GREATER, $3);} 257220604Sjkim | Expression EXPOP_LESS Expression { $$ = DtDoOperator ($1, EXPOP_LESS, $3);} 258220604Sjkim | Expression EXPOP_GREATER_EQUAL Expression { $$ = DtDoOperator ($1, EXPOP_GREATER_EQUAL, $3);} 259220604Sjkim | Expression EXPOP_LESS_EQUAL Expression { $$ = DtDoOperator ($1, EXPOP_LESS_EQUAL, $3);} 260220604Sjkim | Expression EXPOP_EQUAL Expression { $$ = DtDoOperator ($1, EXPOP_EQUAL, $3);} 261220604Sjkim | Expression EXPOP_NOT_EQUAL Expression { $$ = DtDoOperator ($1, EXPOP_NOT_EQUAL, $3);} 262220604Sjkim | Expression EXPOP_AND Expression { $$ = DtDoOperator ($1, EXPOP_AND, $3);} 263220604Sjkim | Expression EXPOP_XOR Expression { $$ = DtDoOperator ($1, EXPOP_XOR, $3);} 264220604Sjkim | Expression EXPOP_OR Expression { $$ = DtDoOperator ($1, EXPOP_OR, $3);} 265220604Sjkim | Expression EXPOP_LOGICAL_AND Expression { $$ = DtDoOperator ($1, EXPOP_LOGICAL_AND, $3);} 266220604Sjkim | Expression EXPOP_LOGICAL_OR Expression { $$ = DtDoOperator ($1, EXPOP_LOGICAL_OR, $3);} 267220604Sjkim 268220604Sjkim /* Parentheses: '(' Expression ')' */ 269220604Sjkim 270220604Sjkim | EXPOP_PAREN_OPEN Expression 271220604Sjkim EXPOP_PAREN_CLOSE { $$ = $2;} 272220604Sjkim 273220604Sjkim /* Label references (prefixed with $) */ 274220604Sjkim 275220604Sjkim | EXPOP_LABEL { $$ = DtResolveLabel (DtParsertext);} 276220604Sjkim 277327557Sjkim /* 278327557Sjkim * All constants for the data table compiler are in hex, whether a (optional) 0x 279327557Sjkim * prefix is present or not. For example, these two input strings are equivalent: 280327557Sjkim * 1234 281327557Sjkim * 0x1234 282327557Sjkim */ 283220604Sjkim 284327557Sjkim /* Non-prefixed hex number */ 285220604Sjkim 286327557Sjkim | EXPOP_NUMBER { $$ = DtDoConstant (DtParsertext);} 287327557Sjkim 288220604Sjkim /* Standard hex number (0x1234) */ 289220604Sjkim 290327557Sjkim | EXPOP_HEX_NUMBER { $$ = DtDoConstant (DtParsertext);} 291220604Sjkim 292327557Sjkim /* Possible TBD: Decimal number with prefix (0d1234) - Not supported this time */ 293220604Sjkim 294327557Sjkim | EXPOP_DECIMAL_NUMBER { $$ = DtDoConstant (DtParsertext);} 295220604Sjkim ; 296220604Sjkim%% 297220604Sjkim 298220681Sjkim/*! [End] no source code translation !*/ 299220681Sjkim 300220604Sjkim/* 301220604Sjkim * Local support functions, including parser entry point 302220604Sjkim */ 303220604Sjkim#define PR_FIRST_PARSE_OPCODE EXPOP_EOF 304220604Sjkim#define PR_YYTNAME_START 3 305220604Sjkim 306220604Sjkim 307220604Sjkim/****************************************************************************** 308220604Sjkim * 309220604Sjkim * FUNCTION: DtParsererror 310220604Sjkim * 311220604Sjkim * PARAMETERS: Message - Parser-generated error message 312220604Sjkim * 313220604Sjkim * RETURN: None 314220604Sjkim * 315220604Sjkim * DESCRIPTION: Handler for parser errors 316220604Sjkim * 317220604Sjkim *****************************************************************************/ 318220604Sjkim 319220604Sjkimvoid 320220604SjkimDtParsererror ( 321220604Sjkim char const *Message) 322220604Sjkim{ 323220604Sjkim DtError (ASL_ERROR, ASL_MSG_SYNTAX, 324220604Sjkim Gbl_CurrentField, (char *) Message); 325220604Sjkim} 326220604Sjkim 327220604Sjkim 328220604Sjkim/****************************************************************************** 329220604Sjkim * 330220604Sjkim * FUNCTION: DtGetOpName 331220604Sjkim * 332220604Sjkim * PARAMETERS: ParseOpcode - Parser token (EXPOP_*) 333220604Sjkim * 334220604Sjkim * RETURN: Pointer to the opcode name 335220604Sjkim * 336220604Sjkim * DESCRIPTION: Get the ascii name of the parse opcode for debug output 337220604Sjkim * 338220604Sjkim *****************************************************************************/ 339220604Sjkim 340220604Sjkimchar * 341220604SjkimDtGetOpName ( 342220604Sjkim UINT32 ParseOpcode) 343220604Sjkim{ 344220681Sjkim#ifdef ASL_YYTNAME_START 345220604Sjkim /* 346220604Sjkim * First entries (PR_YYTNAME_START) in yytname are special reserved names. 347220604Sjkim * Ignore first 6 characters of name (EXPOP_) 348220604Sjkim */ 349220604Sjkim return ((char *) yytname 350220604Sjkim [(ParseOpcode - PR_FIRST_PARSE_OPCODE) + PR_YYTNAME_START] + 6); 351220681Sjkim#else 352220681Sjkim return ("[Unknown parser generator]"); 353220681Sjkim#endif 354220604Sjkim} 355220604Sjkim 356220604Sjkim 357220604Sjkim/****************************************************************************** 358220604Sjkim * 359220604Sjkim * FUNCTION: DtEvaluateExpression 360220604Sjkim * 361220604Sjkim * PARAMETERS: ExprString - Expression to be evaluated. Must be 362220604Sjkim * terminated by either a newline or a NUL 363220604Sjkim * string terminator 364220604Sjkim * 365220604Sjkim * RETURN: 64-bit value for the expression 366220604Sjkim * 367220604Sjkim * DESCRIPTION: Main entry point for the DT expression parser 368220604Sjkim * 369220604Sjkim *****************************************************************************/ 370220604Sjkim 371220604SjkimUINT64 372220604SjkimDtEvaluateExpression ( 373220604Sjkim char *ExprString) 374220604Sjkim{ 375220604Sjkim 376220604Sjkim DbgPrint (ASL_DEBUG_OUTPUT, 377220604Sjkim "**** Input expression: %s (Base 16)\n", ExprString); 378220604Sjkim 379220604Sjkim /* Point lexer to the input string */ 380220604Sjkim 381220604Sjkim if (DtInitLexer (ExprString)) 382220604Sjkim { 383220604Sjkim DtError (ASL_ERROR, ASL_MSG_COMPILER_INTERNAL, 384220604Sjkim Gbl_CurrentField, "Could not initialize lexer"); 385220604Sjkim return (0); 386220604Sjkim } 387220604Sjkim 388220604Sjkim /* Parse/Evaluate the input string (value returned in DtParserResult) */ 389220604Sjkim 390220604Sjkim DtParserparse (); 391220604Sjkim DtTerminateLexer (); 392220604Sjkim 393220604Sjkim DbgPrint (ASL_DEBUG_OUTPUT, 394220604Sjkim "**** Parser returned value: %u (%8.8X%8.8X)\n", 395220604Sjkim (UINT32) DtParserResult, ACPI_FORMAT_UINT64 (DtParserResult)); 396220604Sjkim 397220604Sjkim return (DtParserResult); 398220604Sjkim} 399