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_LABEL_REF
74 %token
<labelref
> DT_PATH_REF
78 %type
<data
> propdataprefix
82 %type
<re
> memreserves
83 %type
<array
> arrayprefix
84 %type
<data
> bytestring
86 %type
<proplist
> proplist
87 %type
<labelref
> dt_ref
89 %type
<node
> devicetree
92 %type
<nodelist
> subnodes
94 %type
<integer
> integer_prim
95 %type
<integer
> integer_unary
96 %type
<integer
> integer_mul
97 %type
<integer
> integer_add
98 %type
<integer
> integer_shift
99 %type
<integer
> integer_rela
100 %type
<integer
> integer_eq
101 %type
<integer
> integer_bitand
102 %type
<integer
> integer_bitxor
103 %type
<integer
> integer_bitor
104 %type
<integer
> integer_and
105 %type
<integer
> integer_or
106 %type
<integer
> integer_trinary
107 %type
<integer
> integer_expr
112 headers memreserves devicetree
114 parser_output
= build_dt_info
($1, $2, $3,
115 guess_boot_cpuid
($3));
124 | DT_V1
';' DT_PLUGIN
';'
126 $$
= DTSF_V1 | DTSF_PLUGIN
;
135 ERROR
(&@
2, "Header flags don't match earlier ones");
145 | memreserve memreserves
147 $$
= chain_reserve_entry
($1, $2);
152 DT_MEMRESERVE integer_prim integer_prim
';'
154 $$
= build_reserve_entry
($2, $3);
156 | DT_LABEL memreserve
158 add_label
(&$2->labels
, $1);
163 dt_ref: DT_LABEL_REF | DT_PATH_REF
;
168 $$
= name_node
($2, "");
170 | devicetree
'/' nodedef
172 $$
= merge_nodes
($1, $3);
177 * We rely on the rule being always:
178 * versioninfo plugindecl memreserves devicetree
179 * so $-1 is what we want (plugindecl)
181 if
(!($
<flags
>-1 & DTSF_PLUGIN
))
182 ERROR
(&@
2, "Label or path %s not found", $1);
183 $$
= add_orphan_node
(
184 name_node
(build_node
(NULL
, NULL
, NULL
),
188 | devicetree DT_LABEL dt_ref nodedef
190 struct node
*target
= get_node_by_ref
($1, $3);
193 add_label
(&target
->labels
, $2);
194 merge_nodes
(target
, $4);
196 ERROR
(&@
3, "Label or path %s not found", $3);
199 | devicetree DT_PATH_REF nodedef
202 * We rely on the rule being always:
203 * versioninfo plugindecl memreserves devicetree
204 * so $-1 is what we want (plugindecl)
206 if
($
<flags
>-1 & DTSF_PLUGIN
) {
207 add_orphan_node
($1, $3, $2);
209 struct node
*target
= get_node_by_ref
($1, $2);
212 merge_nodes
(target
, $3);
214 ERROR
(&@
2, "Label or path %s not found", $2);
218 | devicetree DT_LABEL_REF nodedef
220 struct node
*target
= get_node_by_ref
($1, $2);
223 merge_nodes
(target
, $3);
226 * We rely on the rule being always:
227 * versioninfo plugindecl memreserves devicetree
228 * so $-1 is what we want (plugindecl)
230 if
($
<flags
>-1 & DTSF_PLUGIN
)
231 add_orphan_node
($1, $3, $2);
233 ERROR
(&@
2, "Label or path %s not found", $2);
237 | devicetree DT_DEL_NODE dt_ref
';'
239 struct node
*target
= get_node_by_ref
($1, $3);
244 ERROR
(&@
3, "Label or path %s not found", $3);
249 | devicetree DT_OMIT_NO_REF dt_ref
';'
251 struct node
*target
= get_node_by_ref
($1, $3);
254 omit_node_if_unused
(target
);
256 ERROR
(&@
3, "Label or path %s not found", $3);
264 '{' proplist subnodes
'}' ';'
266 $$
= build_node
($2, $3, &@$
);
277 $$
= chain_property
($2, $1);
282 DT_PROPNODENAME
'=' propdata
';'
284 $$
= build_property
($1, $3, &@$
);
286 | DT_PROPNODENAME
';'
288 $$
= build_property
($1, empty_data
, &@$
);
290 | DT_DEL_PROP DT_PROPNODENAME
';'
292 $$
= build_property_delete
($2);
296 add_label
(&$2->labels
, $1);
302 propdataprefix DT_STRING
304 $$
= data_merge
($1, $2);
306 | propdataprefix arrayprefix
'>'
308 $$
= data_merge
($1, $2.data
);
310 | propdataprefix
'[' bytestring
']'
312 $$
= data_merge
($1, $3);
314 | propdataprefix dt_ref
316 $1 = data_add_marker
($1, TYPE_STRING
, $2);
317 $$
= data_add_marker
($1, REF_PATH
, $2);
319 | propdataprefix DT_INCBIN
'(' DT_STRING
',' integer_prim
',' integer_prim
')'
321 FILE *f
= srcfile_relative_open
($4.val
, NULL
);
325 if
(fseek
(f
, $6, SEEK_SET
) != 0)
326 die
("Couldn't seek to offset %llu in \"%s\": %s",
327 (unsigned long long)$6, $4.val
,
330 d
= data_copy_file
(f
, $8);
332 $$
= data_merge
($1, d
);
335 | propdataprefix DT_INCBIN
'(' DT_STRING
')'
337 FILE *f
= srcfile_relative_open
($4.val
, NULL
);
338 struct data d
= empty_data
;
340 d
= data_copy_file
(f
, -1);
342 $$
= data_merge
($1, d
);
347 $$
= data_add_marker
($1, LABEL
, $2);
360 | propdataprefix DT_LABEL
362 $$
= data_add_marker
($1, LABEL
, $2);
367 DT_BITS DT_LITERAL
'<'
369 unsigned long long bits
;
370 enum markertype type
= TYPE_UINT32
;
375 case
8: type
= TYPE_UINT8
; break
;
376 case
16: type
= TYPE_UINT16
; break
;
377 case
32: type
= TYPE_UINT32
; break
;
378 case
64: type
= TYPE_UINT64
; break
;
380 ERROR
(&@
2, "Array elements must be"
381 " 8, 16, 32 or 64-bits");
385 $$.data
= data_add_marker
(empty_data
, type
, NULL
);
390 $$.data
= data_add_marker
(empty_data
, TYPE_UINT32
, NULL
);
393 | arrayprefix integer_prim
396 uint64_t mask
= (1ULL << $1.bits
) - 1;
398 * Bits above mask must either be all zero
399 * (positive within range of mask) or all one
400 * (negative and sign-extended). The second
401 * condition is true if when we set all bits
402 * within the mask to one (i.e. | in the
403 * mask), all bits are one.
405 if
(($2 > mask
) && (($2 | mask
) != -1ULL))
406 ERROR
(&@
2, "Value out of range for"
407 " %d-bit array element", $1.bits
);
410 $$.data
= data_append_integer
($1.data
, $2, $1.bits
);
414 uint64_t val
= ~
0ULL >> (64 - $1.bits
);
417 $1.data
= data_add_marker
($1.data
,
421 ERROR
(&@
2, "References are only allowed in "
422 "arrays with 32-bit elements.");
424 $$.data
= data_append_integer
($1.data
, val
, $1.bits
);
426 | arrayprefix DT_LABEL
428 $$.data
= data_add_marker
($1.data
, LABEL
, $2);
435 |
'(' integer_expr
')'
447 | integer_or
'?' integer_expr
':' integer_trinary
{ $$
= $1 ?
$3 : $5; }
452 | integer_or DT_OR integer_and
{ $$
= $1 ||
$3; }
457 | integer_and DT_AND integer_bitor
{ $$
= $1 && $3; }
462 | integer_bitor
'|' integer_bitxor
{ $$
= $1 |
$3; }
467 | integer_bitxor
'^' integer_bitand
{ $$
= $1 ^
$3; }
472 | integer_bitand
'&' integer_eq
{ $$
= $1 & $3; }
477 | integer_eq DT_EQ integer_rela
{ $$
= $1 == $3; }
478 | integer_eq DT_NE integer_rela
{ $$
= $1 != $3; }
483 | integer_rela
'<' integer_shift
{ $$
= $1 < $3; }
484 | integer_rela
'>' integer_shift
{ $$
= $1 > $3; }
485 | integer_rela DT_LE integer_shift
{ $$
= $1 <= $3; }
486 | integer_rela DT_GE integer_shift
{ $$
= $1 >= $3; }
490 integer_shift DT_LSHIFT integer_add
{ $$
= $1 << $3; }
491 | integer_shift DT_RSHIFT integer_add
{ $$
= $1 >> $3; }
496 integer_add
'+' integer_mul
{ $$
= $1 + $3; }
497 | integer_add
'-' integer_mul
{ $$
= $1 - $3; }
502 integer_mul
'*' integer_unary
{ $$
= $1 * $3; }
503 | integer_mul
'/' integer_unary
508 ERROR
(&@$
, "Division by zero");
512 | integer_mul
'%' integer_unary
517 ERROR
(&@$
, "Division by zero");
526 |
'-' integer_unary
{ $$
= -$2; }
527 |
'~' integer_unary
{ $$
= ~
$2; }
528 |
'!' integer_unary
{ $$
= !$2; }
534 $$
= data_add_marker
(empty_data
, TYPE_UINT8
, NULL
);
538 $$
= data_append_byte
($1, $2);
540 | bytestring DT_LABEL
542 $$
= data_add_marker
($1, LABEL
, $2);
553 $$
= chain_node
($1, $2);
557 ERROR
(&@
2, "Properties must precede subnodes");
563 DT_PROPNODENAME nodedef
565 $$
= name_node
($2, $1);
567 | DT_DEL_NODE DT_PROPNODENAME
';'
569 $$
= name_node
(build_node_delete
(&@$
), $2);
571 | DT_OMIT_NO_REF subnode
573 $$
= omit_node_if_unused
($2);
577 add_label
(&$2->labels
, $1);
584 void yyerror(char const *s
)
586 ERROR
(&yylloc, "%s", s
);