1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * (C) Copyright David Gibson <dwg@au1.ibm.com>, IBM Corporation. 2005.
14 extern
int yylex(void);
15 extern
void yyerror(char const *s
);
16 #define ERROR(loc, ...) \
18 srcpos_error
((loc
), "Error", __VA_ARGS__
); \
19 treesource_error
= true
; \
22 #define YYERROR_CALL(msg) yyerror(msg)
24 extern
struct dt_info
*parser_output
;
25 extern
bool treesource_error
;
39 struct property
*prop
;
40 struct property
*proplist
;
42 struct node
*nodelist
;
43 struct reserve_info
*re
;
51 %token DT_LSHIFT DT_RSHIFT DT_LE DT_GE DT_EQ DT_NE DT_AND DT_OR
56 %token
<propnodename
> DT_PROPNODENAME
57 %token
<integer
> DT_LITERAL
58 %token
<integer
> DT_CHAR_LITERAL
60 %token
<data
> DT_STRING
61 %token
<labelref
> DT_LABEL
62 %token
<labelref
> DT_LABEL_REF
63 %token
<labelref
> DT_PATH_REF
67 %type
<data
> propdataprefix
71 %type
<re
> memreserves
72 %type
<array
> arrayprefix
73 %type
<data
> bytestring
75 %type
<proplist
> proplist
76 %type
<labelref
> dt_ref
78 %type
<node
> devicetree
81 %type
<nodelist
> subnodes
83 %type
<integer
> integer_prim
84 %type
<integer
> integer_unary
85 %type
<integer
> integer_mul
86 %type
<integer
> integer_add
87 %type
<integer
> integer_shift
88 %type
<integer
> integer_rela
89 %type
<integer
> integer_eq
90 %type
<integer
> integer_bitand
91 %type
<integer
> integer_bitxor
92 %type
<integer
> integer_bitor
93 %type
<integer
> integer_and
94 %type
<integer
> integer_or
95 %type
<integer
> integer_trinary
96 %type
<integer
> integer_expr
101 headers memreserves devicetree
103 parser_output
= build_dt_info
($1, $2, $3,
104 guess_boot_cpuid
($3));
113 | DT_V1
';' DT_PLUGIN
';'
115 $$
= DTSF_V1 | DTSF_PLUGIN
;
124 ERROR
(&@
2, "Header flags don't match earlier ones");
134 | memreserve memreserves
136 $$
= chain_reserve_entry
($1, $2);
141 DT_MEMRESERVE integer_prim integer_prim
';'
143 $$
= build_reserve_entry
($2, $3);
145 | DT_LABEL memreserve
147 add_label
(&$2->labels
, $1);
152 dt_ref: DT_LABEL_REF | DT_PATH_REF
;
157 $$
= name_node
($2, "");
159 | devicetree
'/' nodedef
161 $$
= merge_nodes
($1, $3);
166 * We rely on the rule being always:
167 * versioninfo plugindecl memreserves devicetree
168 * so $-1 is what we want (plugindecl)
170 if
(!($
<flags
>-1 & DTSF_PLUGIN
))
171 ERROR
(&@
2, "Label or path %s not found", $1);
172 $$
= add_orphan_node
(
173 name_node
(build_node
(NULL
, NULL
, NULL
),
177 | devicetree DT_LABEL dt_ref nodedef
179 struct node
*target
= get_node_by_ref
($1, $3);
182 add_label
(&target
->labels
, $2);
183 merge_nodes
(target
, $4);
185 ERROR
(&@
3, "Label or path %s not found", $3);
188 | devicetree DT_PATH_REF nodedef
191 * We rely on the rule being always:
192 * versioninfo plugindecl memreserves devicetree
193 * so $-1 is what we want (plugindecl)
195 if
($
<flags
>-1 & DTSF_PLUGIN
) {
196 add_orphan_node
($1, $3, $2);
198 struct node
*target
= get_node_by_ref
($1, $2);
201 merge_nodes
(target
, $3);
203 ERROR
(&@
2, "Label or path %s not found", $2);
207 | devicetree DT_LABEL_REF nodedef
209 struct node
*target
= get_node_by_ref
($1, $2);
212 merge_nodes
(target
, $3);
215 * We rely on the rule being always:
216 * versioninfo plugindecl memreserves devicetree
217 * so $-1 is what we want (plugindecl)
219 if
($
<flags
>-1 & DTSF_PLUGIN
)
220 add_orphan_node
($1, $3, $2);
222 ERROR
(&@
2, "Label or path %s not found", $2);
226 | devicetree DT_DEL_NODE dt_ref
';'
228 struct node
*target
= get_node_by_ref
($1, $3);
233 ERROR
(&@
3, "Label or path %s not found", $3);
238 | devicetree DT_OMIT_NO_REF dt_ref
';'
240 struct node
*target
= get_node_by_ref
($1, $3);
243 omit_node_if_unused
(target
);
245 ERROR
(&@
3, "Label or path %s not found", $3);
253 '{' proplist subnodes
'}' ';'
255 $$
= build_node
($2, $3, &@$
);
266 $$
= chain_property
($2, $1);
271 DT_PROPNODENAME
'=' propdata
';'
273 $$
= build_property
($1, $3, &@$
);
275 | DT_PROPNODENAME
';'
277 $$
= build_property
($1, empty_data
, &@$
);
279 | DT_DEL_PROP DT_PROPNODENAME
';'
281 $$
= build_property_delete
($2);
285 add_label
(&$2->labels
, $1);
291 propdataprefix DT_STRING
293 $$
= data_merge
($1, $2);
295 | propdataprefix arrayprefix
'>'
297 $$
= data_merge
($1, $2.data
);
299 | propdataprefix
'[' bytestring
']'
301 $$
= data_merge
($1, $3);
303 | propdataprefix dt_ref
305 $1 = data_add_marker
($1, TYPE_STRING
, $2);
306 $$
= data_add_marker
($1, REF_PATH
, $2);
308 | propdataprefix DT_INCBIN
'(' DT_STRING
',' integer_prim
',' integer_prim
')'
310 FILE *f
= srcfile_relative_open
($4.val
, NULL
);
314 if
(fseek
(f
, $6, SEEK_SET
) != 0)
315 die
("Couldn't seek to offset %llu in \"%s\": %s",
316 (unsigned long long)$6, $4.val
,
319 d
= data_copy_file
(f
, $8);
321 $$
= data_merge
($1, d
);
324 | propdataprefix DT_INCBIN
'(' DT_STRING
')'
326 FILE *f
= srcfile_relative_open
($4.val
, NULL
);
327 struct data d
= empty_data
;
329 d
= data_copy_file
(f
, -1);
331 $$
= data_merge
($1, d
);
336 $$
= data_add_marker
($1, LABEL
, $2);
349 | propdataprefix DT_LABEL
351 $$
= data_add_marker
($1, LABEL
, $2);
356 DT_BITS DT_LITERAL
'<'
358 unsigned long long bits
;
359 enum markertype type
= TYPE_UINT32
;
364 case
8: type
= TYPE_UINT8
; break
;
365 case
16: type
= TYPE_UINT16
; break
;
366 case
32: type
= TYPE_UINT32
; break
;
367 case
64: type
= TYPE_UINT64
; break
;
369 ERROR
(&@
2, "Array elements must be"
370 " 8, 16, 32 or 64-bits");
374 $$.data
= data_add_marker
(empty_data
, type
, NULL
);
379 $$.data
= data_add_marker
(empty_data
, TYPE_UINT32
, NULL
);
382 | arrayprefix integer_prim
385 uint64_t mask
= (1ULL << $1.bits
) - 1;
387 * Bits above mask must either be all zero
388 * (positive within range of mask) or all one
389 * (negative and sign-extended). The second
390 * condition is true if when we set all bits
391 * within the mask to one (i.e. | in the
392 * mask), all bits are one.
394 if
(($2 > mask
) && (($2 | mask
) != -1ULL))
395 ERROR
(&@
2, "Value out of range for"
396 " %d-bit array element", $1.bits
);
399 $$.data
= data_append_integer
($1.data
, $2, $1.bits
);
403 uint64_t val
= ~
0ULL >> (64 - $1.bits
);
406 $1.data
= data_add_marker
($1.data
,
410 ERROR
(&@
2, "References are only allowed in "
411 "arrays with 32-bit elements.");
413 $$.data
= data_append_integer
($1.data
, val
, $1.bits
);
415 | arrayprefix DT_LABEL
417 $$.data
= data_add_marker
($1.data
, LABEL
, $2);
424 |
'(' integer_expr
')'
436 | integer_or
'?' integer_expr
':' integer_trinary
{ $$
= $1 ?
$3 : $5; }
441 | integer_or DT_OR integer_and
{ $$
= $1 ||
$3; }
446 | integer_and DT_AND integer_bitor
{ $$
= $1 && $3; }
451 | integer_bitor
'|' integer_bitxor
{ $$
= $1 |
$3; }
456 | integer_bitxor
'^' integer_bitand
{ $$
= $1 ^
$3; }
461 | integer_bitand
'&' integer_eq
{ $$
= $1 & $3; }
466 | integer_eq DT_EQ integer_rela
{ $$
= $1 == $3; }
467 | integer_eq DT_NE integer_rela
{ $$
= $1 != $3; }
472 | integer_rela
'<' integer_shift
{ $$
= $1 < $3; }
473 | integer_rela
'>' integer_shift
{ $$
= $1 > $3; }
474 | integer_rela DT_LE integer_shift
{ $$
= $1 <= $3; }
475 | integer_rela DT_GE integer_shift
{ $$
= $1 >= $3; }
479 integer_shift DT_LSHIFT integer_add
{ $$
= $1 << $3; }
480 | integer_shift DT_RSHIFT integer_add
{ $$
= $1 >> $3; }
485 integer_add
'+' integer_mul
{ $$
= $1 + $3; }
486 | integer_add
'-' integer_mul
{ $$
= $1 - $3; }
491 integer_mul
'*' integer_unary
{ $$
= $1 * $3; }
492 | integer_mul
'/' integer_unary
497 ERROR
(&@$
, "Division by zero");
501 | integer_mul
'%' integer_unary
506 ERROR
(&@$
, "Division by zero");
515 |
'-' integer_unary
{ $$
= -$2; }
516 |
'~' integer_unary
{ $$
= ~
$2; }
517 |
'!' integer_unary
{ $$
= !$2; }
523 $$
= data_add_marker
(empty_data
, TYPE_UINT8
, NULL
);
527 $$
= data_append_byte
($1, $2);
529 | bytestring DT_LABEL
531 $$
= data_add_marker
($1, LABEL
, $2);
542 $$
= chain_node
($1, $2);
546 ERROR
(&@
2, "Properties must precede subnodes");
552 DT_PROPNODENAME nodedef
554 $$
= name_node
($2, $1);
556 | DT_DEL_NODE DT_PROPNODENAME
';'
558 $$
= name_node
(build_node_delete
(&@$
), $2);
560 | DT_OMIT_NO_REF subnode
562 $$
= omit_node_if_unused
($2);
566 add_label
(&$2->labels
, $1);
573 void yyerror(char const *s
)
575 ERROR
(&yylloc, "%s", s
);