2 * (C) Copyright David Gibson <dwg@au1.ibm.com>, IBM Corporation. 2005.
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
67 %token
<propnodename
> DT_PROPNODENAME
68 %token
<integer
> DT_LITERAL
69 %token
<integer
> DT_CHAR_LITERAL
71 %token
<data
> DT_STRING
72 %token
<labelref
> DT_LABEL
73 %token
<labelref
> DT_REF
77 %type
<data
> propdataprefix
81 %type
<re
> memreserves
82 %type
<array
> arrayprefix
83 %type
<data
> bytestring
85 %type
<proplist
> proplist
87 %type
<node
> devicetree
90 %type
<nodelist
> subnodes
92 %type
<integer
> integer_prim
93 %type
<integer
> integer_unary
94 %type
<integer
> integer_mul
95 %type
<integer
> integer_add
96 %type
<integer
> integer_shift
97 %type
<integer
> integer_rela
98 %type
<integer
> integer_eq
99 %type
<integer
> integer_bitand
100 %type
<integer
> integer_bitxor
101 %type
<integer
> integer_bitor
102 %type
<integer
> integer_and
103 %type
<integer
> integer_or
104 %type
<integer
> integer_trinary
105 %type
<integer
> integer_expr
110 headers memreserves devicetree
112 parser_output
= build_dt_info
($1, $2, $3,
113 guess_boot_cpuid
($3));
122 | DT_V1
';' DT_PLUGIN
';'
124 $$
= DTSF_V1 | DTSF_PLUGIN
;
133 ERROR
(&@
2, "Header flags don't match earlier ones");
143 | memreserve memreserves
145 $$
= chain_reserve_entry
($1, $2);
150 DT_MEMRESERVE integer_prim integer_prim
';'
152 $$
= build_reserve_entry
($2, $3);
154 | DT_LABEL memreserve
156 add_label
(&$2->labels
, $1);
164 $$
= name_node
($2, "");
166 | devicetree
'/' nodedef
168 $$
= merge_nodes
($1, $3);
173 * We rely on the rule being always:
174 * versioninfo plugindecl memreserves devicetree
175 * so $-1 is what we want (plugindecl)
177 if
(!($
<flags
>-1 & DTSF_PLUGIN
))
178 ERROR
(&@
2, "Label or path %s not found", $1);
179 $$
= add_orphan_node
(name_node
(build_node
(NULL
, NULL
), ""), $2, $1);
181 | devicetree DT_LABEL DT_REF nodedef
183 struct node
*target
= get_node_by_ref
($1, $3);
186 add_label
(&target
->labels
, $2);
187 merge_nodes
(target
, $4);
189 ERROR
(&@
3, "Label or path %s not found", $3);
192 | devicetree DT_REF nodedef
195 * We rely on the rule being always:
196 * versioninfo plugindecl memreserves devicetree
197 * so $-1 is what we want (plugindecl)
199 if
($
<flags
>-1 & DTSF_PLUGIN
) {
200 add_orphan_node
($1, $3, $2);
202 struct node
*target
= get_node_by_ref
($1, $2);
205 merge_nodes
(target
, $3);
207 ERROR
(&@
2, "Label or path %s not found", $2);
211 | devicetree DT_DEL_NODE DT_REF
';'
213 struct node
*target
= get_node_by_ref
($1, $3);
218 ERROR
(&@
3, "Label or path %s not found", $3);
223 | devicetree DT_OMIT_NO_REF DT_REF
';'
225 struct node
*target
= get_node_by_ref
($1, $3);
228 omit_node_if_unused
(target
);
230 ERROR
(&@
3, "Label or path %s not found", $3);
238 '{' proplist subnodes
'}' ';'
240 $$
= build_node
($2, $3);
251 $$
= chain_property
($2, $1);
256 DT_PROPNODENAME
'=' propdata
';'
258 $$
= build_property
($1, $3);
260 | DT_PROPNODENAME
';'
262 $$
= build_property
($1, empty_data
);
264 | DT_DEL_PROP DT_PROPNODENAME
';'
266 $$
= build_property_delete
($2);
270 add_label
(&$2->labels
, $1);
276 propdataprefix DT_STRING
278 $$
= data_merge
($1, $2);
280 | propdataprefix arrayprefix
'>'
282 $$
= data_merge
($1, $2.data
);
284 | propdataprefix
'[' bytestring
']'
286 $$
= data_merge
($1, $3);
288 | propdataprefix DT_REF
290 $1 = data_add_marker
($1, TYPE_STRING
, $2);
291 $$
= data_add_marker
($1, REF_PATH
, $2);
293 | propdataprefix DT_INCBIN
'(' DT_STRING
',' integer_prim
',' integer_prim
')'
295 FILE *f
= srcfile_relative_open
($4.val
, NULL
);
299 if
(fseek
(f
, $6, SEEK_SET
) != 0)
300 die
("Couldn't seek to offset %llu in \"%s\": %s",
301 (unsigned long long)$6, $4.val
,
304 d
= data_copy_file
(f
, $8);
306 $$
= data_merge
($1, d
);
309 | propdataprefix DT_INCBIN
'(' DT_STRING
')'
311 FILE *f
= srcfile_relative_open
($4.val
, NULL
);
312 struct data d
= empty_data
;
314 d
= data_copy_file
(f
, -1);
316 $$
= data_merge
($1, d
);
321 $$
= data_add_marker
($1, LABEL
, $2);
334 | propdataprefix DT_LABEL
336 $$
= data_add_marker
($1, LABEL
, $2);
341 DT_BITS DT_LITERAL
'<'
343 unsigned long long bits
;
344 enum markertype type
= TYPE_UINT32
;
349 case
8: type
= TYPE_UINT8
; break
;
350 case
16: type
= TYPE_UINT16
; break
;
351 case
32: type
= TYPE_UINT32
; break
;
352 case
64: type
= TYPE_UINT64
; break
;
354 ERROR
(&@
2, "Array elements must be"
355 " 8, 16, 32 or 64-bits");
359 $$.data
= data_add_marker
(empty_data
, type
, NULL
);
364 $$.data
= data_add_marker
(empty_data
, TYPE_UINT32
, NULL
);
367 | arrayprefix integer_prim
370 uint64_t mask
= (1ULL << $1.bits
) - 1;
372 * Bits above mask must either be all zero
373 * (positive within range of mask) or all one
374 * (negative and sign-extended). The second
375 * condition is true if when we set all bits
376 * within the mask to one (i.e. | in the
377 * mask), all bits are one.
379 if
(($2 > mask
) && (($2 | mask
) != -1ULL))
380 ERROR
(&@
2, "Value out of range for"
381 " %d-bit array element", $1.bits
);
384 $$.data
= data_append_integer
($1.data
, $2, $1.bits
);
388 uint64_t val
= ~
0ULL >> (64 - $1.bits
);
391 $1.data
= data_add_marker
($1.data
,
395 ERROR
(&@
2, "References are only allowed in "
396 "arrays with 32-bit elements.");
398 $$.data
= data_append_integer
($1.data
, val
, $1.bits
);
400 | arrayprefix DT_LABEL
402 $$.data
= data_add_marker
($1.data
, LABEL
, $2);
409 |
'(' integer_expr
')'
421 | integer_or
'?' integer_expr
':' integer_trinary
{ $$
= $1 ?
$3 : $5; }
426 | integer_or DT_OR integer_and
{ $$
= $1 ||
$3; }
431 | integer_and DT_AND integer_bitor
{ $$
= $1 && $3; }
436 | integer_bitor
'|' integer_bitxor
{ $$
= $1 |
$3; }
441 | integer_bitxor
'^' integer_bitand
{ $$
= $1 ^
$3; }
446 | integer_bitand
'&' integer_eq
{ $$
= $1 & $3; }
451 | integer_eq DT_EQ integer_rela
{ $$
= $1 == $3; }
452 | integer_eq DT_NE integer_rela
{ $$
= $1 != $3; }
457 | integer_rela
'<' integer_shift
{ $$
= $1 < $3; }
458 | integer_rela
'>' integer_shift
{ $$
= $1 > $3; }
459 | integer_rela DT_LE integer_shift
{ $$
= $1 <= $3; }
460 | integer_rela DT_GE integer_shift
{ $$
= $1 >= $3; }
464 integer_shift DT_LSHIFT integer_add
{ $$
= $1 << $3; }
465 | integer_shift DT_RSHIFT integer_add
{ $$
= $1 >> $3; }
470 integer_add
'+' integer_mul
{ $$
= $1 + $3; }
471 | integer_add
'-' integer_mul
{ $$
= $1 - $3; }
476 integer_mul
'*' integer_unary
{ $$
= $1 * $3; }
477 | integer_mul
'/' integer_unary
482 ERROR
(&@$
, "Division by zero");
486 | integer_mul
'%' integer_unary
491 ERROR
(&@$
, "Division by zero");
500 |
'-' integer_unary
{ $$
= -$2; }
501 |
'~' integer_unary
{ $$
= ~
$2; }
502 |
'!' integer_unary
{ $$
= !$2; }
508 $$
= data_add_marker
(empty_data
, TYPE_UINT8
, NULL
);
512 $$
= data_append_byte
($1, $2);
514 | bytestring DT_LABEL
516 $$
= data_add_marker
($1, LABEL
, $2);
527 $$
= chain_node
($1, $2);
531 ERROR
(&@
2, "Properties must precede subnodes");
537 DT_PROPNODENAME nodedef
539 $$
= name_node
($2, $1);
541 | DT_DEL_NODE DT_PROPNODENAME
';'
543 $$
= name_node
(build_node_delete
(), $2);
545 | DT_OMIT_NO_REF subnode
547 $$
= omit_node_if_unused
($2);
551 add_label
(&$2->labels
, $1);
558 void yyerror(char const *s
)
560 ERROR
(&yylloc, "%s", s
);