5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License as
7 * published by the Free Software Foundation; either version 2 of the
8 * License, or (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
27 extern int yylex(void);
28 extern void yyerror(char const *s);
29 #define ERROR(loc, ...) \
31 srcpos_error((loc), "Error", __VA_ARGS__); \
32 treesource_error = true; \
35 extern struct dt_info *parser_output;
36 extern bool treesource_error;
50 struct property *prop;
51 struct property *proplist;
53 struct node *nodelist;
54 struct reserve_info *re;
62 %token DT_LSHIFT DT_RSHIFT DT_LE DT_GE DT_EQ DT_NE DT_AND DT_OR
66 %token <propnodename> DT_PROPNODENAME
67 %token <integer> DT_LITERAL
68 %token <integer> DT_CHAR_LITERAL
70 %token <data> DT_STRING
71 %token <labelref> DT_LABEL
72 %token <labelref> DT_REF
76 %type <data> propdataprefix
80 %type <re> memreserves
81 %type <array> arrayprefix
82 %type <data> bytestring
84 %type <proplist> proplist
86 %type <node> devicetree
89 %type <nodelist> subnodes
91 %type <integer> integer_prim
92 %type <integer> integer_unary
93 %type <integer> integer_mul
94 %type <integer> integer_add
95 %type <integer> integer_shift
96 %type <integer> integer_rela
97 %type <integer> integer_eq
98 %type <integer> integer_bitand
99 %type <integer> integer_bitxor
100 %type <integer> integer_bitor
101 %type <integer> integer_and
102 %type <integer> integer_or
103 %type <integer> integer_trinary
104 %type <integer> integer_expr
109 headers memreserves devicetree
111 parser_output = build_dt_info($1, $2, $3,
112 guess_boot_cpuid($3));
121 | DT_V1 ';' DT_PLUGIN ';'
123 $$ = DTSF_V1 | DTSF_PLUGIN;
132 ERROR(&@2, "Header flags don't match earlier ones");
142 | memreserve memreserves
144 $$ = chain_reserve_entry($1, $2);
149 DT_MEMRESERVE integer_prim integer_prim ';'
151 $$ = build_reserve_entry($2, $3);
153 | DT_LABEL memreserve
155 add_label(&$2->labels, $1);
163 $$ = name_node($2, "");
165 | devicetree '/' nodedef
167 $$ = merge_nodes($1, $3);
172 * We rely on the rule being always:
173 * versioninfo plugindecl memreserves devicetree
174 * so $-1 is what we want (plugindecl)
176 if (!($<flags>-1 & DTSF_PLUGIN))
177 ERROR(&@2, "Label or path %s not found", $1);
178 $$ = add_orphan_node(name_node(build_node(NULL, NULL), ""), $2, $1);
180 | devicetree DT_LABEL DT_REF nodedef
182 struct node *target = get_node_by_ref($1, $3);
185 add_label(&target->labels, $2);
186 merge_nodes(target, $4);
188 ERROR(&@3, "Label or path %s not found", $3);
191 | devicetree DT_REF nodedef
193 struct node *target = get_node_by_ref($1, $2);
196 merge_nodes(target, $3);
199 * We rely on the rule being always:
200 * versioninfo plugindecl memreserves devicetree
201 * so $-1 is what we want (plugindecl)
203 if ($<flags>-1 & DTSF_PLUGIN)
204 add_orphan_node($1, $3, $2);
206 ERROR(&@2, "Label or path %s not found", $2);
210 | devicetree DT_DEL_NODE DT_REF ';'
212 struct node *target = get_node_by_ref($1, $3);
217 ERROR(&@3, "Label or path %s not found", $3);
225 '{' proplist subnodes '}' ';'
227 $$ = build_node($2, $3);
238 $$ = chain_property($2, $1);
243 DT_PROPNODENAME '=' propdata ';'
245 $$ = build_property($1, $3);
247 | DT_PROPNODENAME ';'
249 $$ = build_property($1, empty_data);
251 | DT_DEL_PROP DT_PROPNODENAME ';'
253 $$ = build_property_delete($2);
257 add_label(&$2->labels, $1);
263 propdataprefix DT_STRING
265 $$ = data_merge($1, $2);
267 | propdataprefix arrayprefix '>'
269 $$ = data_merge($1, $2.data);
271 | propdataprefix '[' bytestring ']'
273 $$ = data_merge($1, $3);
275 | propdataprefix DT_REF
277 $$ = data_add_marker($1, REF_PATH, $2);
279 | propdataprefix DT_INCBIN '(' DT_STRING ',' integer_prim ',' integer_prim ')'
281 FILE *f = srcfile_relative_open($4.val, NULL);
285 if (fseek(f, $6, SEEK_SET) != 0)
286 die("Couldn't seek to offset %llu in \"%s\": %s",
287 (unsigned long long)$6, $4.val,
290 d = data_copy_file(f, $8);
292 $$ = data_merge($1, d);
295 | propdataprefix DT_INCBIN '(' DT_STRING ')'
297 FILE *f = srcfile_relative_open($4.val, NULL);
298 struct data d = empty_data;
300 d = data_copy_file(f, -1);
302 $$ = data_merge($1, d);
307 $$ = data_add_marker($1, LABEL, $2);
320 | propdataprefix DT_LABEL
322 $$ = data_add_marker($1, LABEL, $2);
327 DT_BITS DT_LITERAL '<'
329 unsigned long long bits;
333 if ((bits != 8) && (bits != 16) &&
334 (bits != 32) && (bits != 64)) {
335 ERROR(&@2, "Array elements must be"
336 " 8, 16, 32 or 64-bits");
340 $$.data = empty_data;
345 $$.data = empty_data;
348 | arrayprefix integer_prim
351 uint64_t mask = (1ULL << $1.bits) - 1;
353 * Bits above mask must either be all zero
354 * (positive within range of mask) or all one
355 * (negative and sign-extended). The second
356 * condition is true if when we set all bits
357 * within the mask to one (i.e. | in the
358 * mask), all bits are one.
360 if (($2 > mask) && (($2 | mask) != -1ULL))
361 ERROR(&@2, "Value out of range for"
362 " %d-bit array element", $1.bits);
365 $$.data = data_append_integer($1.data, $2, $1.bits);
369 uint64_t val = ~0ULL >> (64 - $1.bits);
372 $1.data = data_add_marker($1.data,
376 ERROR(&@2, "References are only allowed in "
377 "arrays with 32-bit elements.");
379 $$.data = data_append_integer($1.data, val, $1.bits);
381 | arrayprefix DT_LABEL
383 $$.data = data_add_marker($1.data, LABEL, $2);
390 | '(' integer_expr ')'
402 | integer_or '?' integer_expr ':' integer_trinary { $$ = $1 ? $3 : $5; }
407 | integer_or DT_OR integer_and { $$ = $1 || $3; }
412 | integer_and DT_AND integer_bitor { $$ = $1 && $3; }
417 | integer_bitor '|' integer_bitxor { $$ = $1 | $3; }
422 | integer_bitxor '^' integer_bitand { $$ = $1 ^ $3; }
427 | integer_bitand '&' integer_eq { $$ = $1 & $3; }
432 | integer_eq DT_EQ integer_rela { $$ = $1 == $3; }
433 | integer_eq DT_NE integer_rela { $$ = $1 != $3; }
438 | integer_rela '<' integer_shift { $$ = $1 < $3; }
439 | integer_rela '>' integer_shift { $$ = $1 > $3; }
440 | integer_rela DT_LE integer_shift { $$ = $1 <= $3; }
441 | integer_rela DT_GE integer_shift { $$ = $1 >= $3; }
445 integer_shift DT_LSHIFT integer_add { $$ = $1 << $3; }
446 | integer_shift DT_RSHIFT integer_add { $$ = $1 >> $3; }
451 integer_add '+' integer_mul { $$ = $1 + $3; }
452 | integer_add '-' integer_mul { $$ = $1 - $3; }
457 integer_mul '*' integer_unary { $$ = $1 * $3; }
458 | integer_mul '/' integer_unary
463 ERROR(&@$, "Division by zero");
467 | integer_mul '%' integer_unary
472 ERROR(&@$, "Division by zero");
481 | '-' integer_unary { $$ = -$2; }
482 | '~' integer_unary { $$ = ~$2; }
483 | '!' integer_unary { $$ = !$2; }
493 $$ = data_append_byte($1, $2);
495 | bytestring DT_LABEL
497 $$ = data_add_marker($1, LABEL, $2);
508 $$ = chain_node($1, $2);
512 ERROR(&@2, "Properties must precede subnodes");
518 DT_PROPNODENAME nodedef
520 $$ = name_node($2, $1);
522 | DT_DEL_NODE DT_PROPNODENAME ';'
524 $$ = name_node(build_node_delete(), $2);
528 add_label(&$2->labels, $1);
535 void yyerror(char const *s)
537 ERROR(&yylloc, "%s", s);