| 1 |
%{ |
| 2 |
/****************************************************************************** |
| 3 |
* |
| 4 |
* Module Name: dtparser.y - Bison input file for table compiler parser |
| 5 |
* |
| 6 |
*****************************************************************************/ |
| 7 |
|
| 8 |
/* |
| 9 |
* Copyright (C) 2000 - 2026, Intel Corp. |
| 10 |
* All rights reserved. |
| 11 |
* |
| 12 |
* Redistribution and use in source and binary forms, with or without |
| 13 |
* modification, are permitted provided that the following conditions |
| 14 |
* are met: |
| 15 |
* 1. Redistributions of source code must retain the above copyright |
| 16 |
* notice, this list of conditions, and the following disclaimer, |
| 17 |
* without modification. |
| 18 |
* 2. Redistributions in binary form must reproduce at minimum a disclaimer |
| 19 |
* substantially similar to the "NO WARRANTY" disclaimer below |
| 20 |
* ("Disclaimer") and any redistribution must be conditioned upon |
| 21 |
* including a substantially similar Disclaimer requirement for further |
| 22 |
* binary redistribution. |
| 23 |
* 3. Neither the names of the above-listed copyright holders nor the names |
| 24 |
* of any contributors may be used to endorse or promote products derived |
| 25 |
* from this software without specific prior written permission. |
| 26 |
* |
| 27 |
* Alternatively, this software may be distributed under the terms of the |
| 28 |
* GNU General Public License ("GPL") version 2 as published by the Free |
| 29 |
* Software Foundation. |
| 30 |
* |
| 31 |
* NO WARRANTY |
| 32 |
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 33 |
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 34 |
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 35 |
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 36 |
* HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
| 37 |
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS |
| 38 |
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
| 39 |
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, |
| 40 |
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING |
| 41 |
* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
| 42 |
* POSSIBILITY OF SUCH DAMAGES. |
| 43 |
*/ |
| 44 |
|
| 45 |
#include "aslcompiler.h" |
| 46 |
|
| 47 |
#define _COMPONENT DT_COMPILER |
| 48 |
ACPI_MODULE_NAME ("dtparser") |
| 49 |
|
| 50 |
void * AslLocalAllocate (unsigned int Size); |
| 51 |
|
| 52 |
/* Bison/yacc configuration */ |
| 53 |
|
| 54 |
#undef alloca |
| 55 |
#define alloca AslLocalAllocate |
| 56 |
|
| 57 |
int DtParserlex (void); |
| 58 |
int DtParserparse (void); |
| 59 |
void DtParsererror (char const *msg); |
| 60 |
extern char *DtParsertext; |
| 61 |
extern DT_FIELD *AslGbl_CurrentField; |
| 62 |
|
| 63 |
UINT64 DtParserResult; /* Expression return value */ |
| 64 |
|
| 65 |
/* Bison/yacc configuration */ |
| 66 |
|
| 67 |
#define yytname DtParsername |
| 68 |
#define YYDEBUG 1 /* Enable debug output */ |
| 69 |
#define YYERROR_VERBOSE 1 /* Verbose error messages */ |
| 70 |
#define YYFLAG -32768 |
| 71 |
|
| 72 |
/* Define YYMALLOC/YYFREE to prevent redefinition errors */ |
| 73 |
|
| 74 |
#define YYMALLOC malloc |
| 75 |
#define YYFREE free |
| 76 |
%} |
| 77 |
|
| 78 |
%union |
| 79 |
{ |
| 80 |
UINT64 value; |
| 81 |
UINT32 op; |
| 82 |
} |
| 83 |
|
| 84 |
/*! [Begin] no source code translation */ |
| 85 |
|
| 86 |
%type <value> Expression |
| 87 |
|
| 88 |
%token <op> OP_EXP_EOF |
| 89 |
%token <op> OP_EXP_NEW_LINE |
| 90 |
%token <op> OP_EXP_NUMBER |
| 91 |
%token <op> OP_EXP_HEX_NUMBER |
| 92 |
%token <op> OP_EXP_DECIMAL_NUMBER |
| 93 |
%token <op> OP_EXP_LABEL |
| 94 |
%token <op> OP_EXP_PAREN_OPEN |
| 95 |
%token <op> OP_EXP_PAREN_CLOSE |
| 96 |
|
| 97 |
%left <op> OP_EXP_LOGICAL_OR |
| 98 |
%left <op> OP_EXP_LOGICAL_AND |
| 99 |
%left <op> OP_EXP_OR |
| 100 |
%left <op> OP_EXP_XOR |
| 101 |
%left <op> OP_EXP_AND |
| 102 |
%left <op> OP_EXP_EQUAL OP_EXP_NOT_EQUAL |
| 103 |
%left <op> OP_EXP_GREATER OP_EXP_LESS OP_EXP_GREATER_EQUAL OP_EXP_LESS_EQUAL |
| 104 |
%left <op> OP_EXP_SHIFT_RIGHT OP_EXP_SHIFT_LEFT |
| 105 |
%left <op> OP_EXP_ADD OP_EXP_SUBTRACT |
| 106 |
%left <op> OP_EXP_MULTIPLY OP_EXP_DIVIDE OP_EXP_MODULO |
| 107 |
%right <op> OP_EXP_ONES_COMPLIMENT OP_EXP_LOGICAL_NOT |
| 108 |
|
| 109 |
%% |
| 110 |
|
| 111 |
/* |
| 112 |
* Operator precedence rules (from K&R) |
| 113 |
* |
| 114 |
* 1) ( ) |
| 115 |
* 2) ! ~ (unary operators that are supported here) |
| 116 |
* 3) * / % |
| 117 |
* 4) + - |
| 118 |
* 5) >> << |
| 119 |
* 6) < > <= >= |
| 120 |
* 7) == != |
| 121 |
* 8) & |
| 122 |
* 9) ^ |
| 123 |
* 10) | |
| 124 |
* 11) && |
| 125 |
* 12) || |
| 126 |
*/ |
| 127 |
Value |
| 128 |
: Expression OP_EXP_NEW_LINE { DtParserResult=$1; return 0; } /* End of line (newline) */ |
| 129 |
| Expression OP_EXP_EOF { DtParserResult=$1; return 0; } /* End of string (0) */ |
| 130 |
; |
| 131 |
|
| 132 |
Expression |
| 133 |
|
| 134 |
/* Unary operators */ |
| 135 |
|
| 136 |
: OP_EXP_LOGICAL_NOT Expression { $$ = DtDoOperator ($2, OP_EXP_LOGICAL_NOT, $2);} |
| 137 |
| OP_EXP_ONES_COMPLIMENT Expression { $$ = DtDoOperator ($2, OP_EXP_ONES_COMPLIMENT, $2);} |
| 138 |
|
| 139 |
/* Binary operators */ |
| 140 |
|
| 141 |
| Expression OP_EXP_MULTIPLY Expression { $$ = DtDoOperator ($1, OP_EXP_MULTIPLY, $3);} |
| 142 |
| Expression OP_EXP_DIVIDE Expression { $$ = DtDoOperator ($1, OP_EXP_DIVIDE, $3);} |
| 143 |
| Expression OP_EXP_MODULO Expression { $$ = DtDoOperator ($1, OP_EXP_MODULO, $3);} |
| 144 |
| Expression OP_EXP_ADD Expression { $$ = DtDoOperator ($1, OP_EXP_ADD, $3);} |
| 145 |
| Expression OP_EXP_SUBTRACT Expression { $$ = DtDoOperator ($1, OP_EXP_SUBTRACT, $3);} |
| 146 |
| Expression OP_EXP_SHIFT_RIGHT Expression { $$ = DtDoOperator ($1, OP_EXP_SHIFT_RIGHT, $3);} |
| 147 |
| Expression OP_EXP_SHIFT_LEFT Expression { $$ = DtDoOperator ($1, OP_EXP_SHIFT_LEFT, $3);} |
| 148 |
| Expression OP_EXP_GREATER Expression { $$ = DtDoOperator ($1, OP_EXP_GREATER, $3);} |
| 149 |
| Expression OP_EXP_LESS Expression { $$ = DtDoOperator ($1, OP_EXP_LESS, $3);} |
| 150 |
| Expression OP_EXP_GREATER_EQUAL Expression { $$ = DtDoOperator ($1, OP_EXP_GREATER_EQUAL, $3);} |
| 151 |
| Expression OP_EXP_LESS_EQUAL Expression { $$ = DtDoOperator ($1, OP_EXP_LESS_EQUAL, $3);} |
| 152 |
| Expression OP_EXP_EQUAL Expression { $$ = DtDoOperator ($1, OP_EXP_EQUAL, $3);} |
| 153 |
| Expression OP_EXP_NOT_EQUAL Expression { $$ = DtDoOperator ($1, OP_EXP_NOT_EQUAL, $3);} |
| 154 |
| Expression OP_EXP_AND Expression { $$ = DtDoOperator ($1, OP_EXP_AND, $3);} |
| 155 |
| Expression OP_EXP_XOR Expression { $$ = DtDoOperator ($1, OP_EXP_XOR, $3);} |
| 156 |
| Expression OP_EXP_OR Expression { $$ = DtDoOperator ($1, OP_EXP_OR, $3);} |
| 157 |
| Expression OP_EXP_LOGICAL_AND Expression { $$ = DtDoOperator ($1, OP_EXP_LOGICAL_AND, $3);} |
| 158 |
| Expression OP_EXP_LOGICAL_OR Expression { $$ = DtDoOperator ($1, OP_EXP_LOGICAL_OR, $3);} |
| 159 |
|
| 160 |
/* Parentheses: '(' Expression ')' */ |
| 161 |
|
| 162 |
| OP_EXP_PAREN_OPEN Expression |
| 163 |
OP_EXP_PAREN_CLOSE { $$ = $2;} |
| 164 |
|
| 165 |
/* Label references (prefixed with $) */ |
| 166 |
|
| 167 |
| OP_EXP_LABEL { $$ = DtResolveLabel (DtParsertext);} |
| 168 |
|
| 169 |
/* |
| 170 |
* All constants for the data table compiler are in hex, whether a (optional) 0x |
| 171 |
* prefix is present or not. For example, these two input strings are equivalent: |
| 172 |
* 1234 |
| 173 |
* 0x1234 |
| 174 |
*/ |
| 175 |
|
| 176 |
/* Non-prefixed hex number */ |
| 177 |
|
| 178 |
| OP_EXP_NUMBER { $$ = DtDoConstant (DtParsertext);} |
| 179 |
|
| 180 |
/* Standard hex number (0x1234) */ |
| 181 |
|
| 182 |
| OP_EXP_HEX_NUMBER { $$ = DtDoConstant (DtParsertext);} |
| 183 |
|
| 184 |
/* Possible TBD: Decimal number with prefix (0d1234) - Not supported this time */ |
| 185 |
|
| 186 |
| OP_EXP_DECIMAL_NUMBER { $$ = DtDoConstant (DtParsertext);} |
| 187 |
; |
| 188 |
%% |
| 189 |
|
| 190 |
/*! [End] no source code translation !*/ |
| 191 |
|
| 192 |
/* |
| 193 |
* Local support functions, including parser entry point |
| 194 |
*/ |
| 195 |
#define PR_FIRST_PARSE_OPCODE OP_EXP_EOF |
| 196 |
#define PR_YYTNAME_START 3 |
| 197 |
|
| 198 |
|
| 199 |
/****************************************************************************** |
| 200 |
* |
| 201 |
* FUNCTION: DtParsererror |
| 202 |
* |
| 203 |
* PARAMETERS: Message - Parser-generated error message |
| 204 |
* |
| 205 |
* RETURN: None |
| 206 |
* |
| 207 |
* DESCRIPTION: Handler for parser errors |
| 208 |
* |
| 209 |
*****************************************************************************/ |
| 210 |
|
| 211 |
void |
| 212 |
DtParsererror ( |
| 213 |
char const *Message) |
| 214 |
{ |
| 215 |
DtError (ASL_ERROR, ASL_MSG_SYNTAX, |
| 216 |
AslGbl_CurrentField, (char *) Message); |
| 217 |
} |
| 218 |
|
| 219 |
|
| 220 |
/****************************************************************************** |
| 221 |
* |
| 222 |
* FUNCTION: DtGetOpName |
| 223 |
* |
| 224 |
* PARAMETERS: ParseOpcode - Parser token (OP_EXP_*) |
| 225 |
* |
| 226 |
* RETURN: Pointer to the opcode name |
| 227 |
* |
| 228 |
* DESCRIPTION: Get the ascii name of the parse opcode for debug output |
| 229 |
* |
| 230 |
*****************************************************************************/ |
| 231 |
|
| 232 |
char * |
| 233 |
DtGetOpName ( |
| 234 |
UINT32 ParseOpcode) |
| 235 |
{ |
| 236 |
#ifdef ASL_YYTNAME_START |
| 237 |
/* |
| 238 |
* First entries (PR_YYTNAME_START) in yytname are special reserved names. |
| 239 |
* Ignore first 6 characters of name (OP_EXP_) |
| 240 |
*/ |
| 241 |
return ((char *) yytname |
| 242 |
[(ParseOpcode - PR_FIRST_PARSE_OPCODE) + PR_YYTNAME_START] + 6); |
| 243 |
#else |
| 244 |
return ("[Unknown parser generator]"); |
| 245 |
#endif |
| 246 |
} |
| 247 |
|
| 248 |
|
| 249 |
/****************************************************************************** |
| 250 |
* |
| 251 |
* FUNCTION: DtEvaluateExpression |
| 252 |
* |
| 253 |
* PARAMETERS: ExprString - Expression to be evaluated. Must be |
| 254 |
* terminated by either a newline or a NUL |
| 255 |
* string terminator |
| 256 |
* |
| 257 |
* RETURN: 64-bit value for the expression |
| 258 |
* |
| 259 |
* DESCRIPTION: Main entry point for the DT expression parser |
| 260 |
* |
| 261 |
*****************************************************************************/ |
| 262 |
|
| 263 |
UINT64 |
| 264 |
DtEvaluateExpression ( |
| 265 |
char *ExprString) |
| 266 |
{ |
| 267 |
|
| 268 |
DbgPrint (ASL_DEBUG_OUTPUT, |
| 269 |
"**** Input expression: %s (Base 16)\n", ExprString); |
| 270 |
|
| 271 |
/* Point lexer to the input string */ |
| 272 |
|
| 273 |
if (DtInitLexer (ExprString)) |
| 274 |
{ |
| 275 |
DtError (ASL_ERROR, ASL_MSG_COMPILER_INTERNAL, |
| 276 |
AslGbl_CurrentField, "Could not initialize lexer"); |
| 277 |
return (0); |
| 278 |
} |
| 279 |
|
| 280 |
/* Parse/Evaluate the input string (value returned in DtParserResult) */ |
| 281 |
|
| 282 |
DtParserparse (); |
| 283 |
DtTerminateLexer (); |
| 284 |
|
| 285 |
DbgPrint (ASL_DEBUG_OUTPUT, |
| 286 |
"**** Parser returned value: %u (%8.8X%8.8X)\n", |
| 287 |
(UINT32) DtParserResult, ACPI_FORMAT_UINT64 (DtParserResult)); |
| 288 |
|
| 289 |
return (DtParserResult); |
| 290 |
} |