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
26 extern
int yylex(void);
27 extern
void yyerror(char const *s
);
28 #define ERROR(loc, ...) \
30 srcpos_error
((loc
), "Error", __VA_ARGS__
); \
31 treesource_error
= true
; \
34 extern
struct boot_info
*the_boot_info
;
35 extern
bool treesource_error
;
49 struct property
*prop
;
50 struct property
*proplist
;
52 struct node
*nodelist
;
53 struct reserve_info
*re
;
59 %token DT_LSHIFT DT_RSHIFT DT_LE DT_GE DT_EQ DT_NE DT_AND DT_OR
63 %token
<propnodename
> DT_PROPNODENAME
64 %token
<integer
> DT_LITERAL
65 %token
<integer
> DT_CHAR_LITERAL
67 %token
<data
> DT_STRING
68 %token
<labelref
> DT_LABEL
69 %token
<labelref
> DT_REF
73 %type
<data
> propdataprefix
75 %type
<re
> memreserves
76 %type
<array
> arrayprefix
77 %type
<data
> bytestring
79 %type
<proplist
> proplist
81 %type
<node
> devicetree
84 %type
<nodelist
> subnodes
86 %type
<integer
> integer_prim
87 %type
<integer
> integer_unary
88 %type
<integer
> integer_mul
89 %type
<integer
> integer_add
90 %type
<integer
> integer_shift
91 %type
<integer
> integer_rela
92 %type
<integer
> integer_eq
93 %type
<integer
> integer_bitand
94 %type
<integer
> integer_bitxor
95 %type
<integer
> integer_bitor
96 %type
<integer
> integer_and
97 %type
<integer
> integer_or
98 %type
<integer
> integer_trinary
99 %type
<integer
> integer_expr
104 DT_V1
';' memreserves devicetree
106 the_boot_info
= build_boot_info
($3, $4,
107 guess_boot_cpuid
($4));
116 | memreserve memreserves
118 $$
= chain_reserve_entry
($1, $2);
123 DT_MEMRESERVE integer_prim integer_prim
';'
125 $$
= build_reserve_entry
($2, $3);
127 | DT_LABEL memreserve
129 add_label
(&$2->labels
, $1);
137 $$
= name_node
($2, "");
139 | devicetree
'/' nodedef
141 $$
= merge_nodes
($1, $3);
144 | devicetree DT_LABEL DT_REF nodedef
146 struct node
*target
= get_node_by_ref
($1, $3);
148 add_label
(&target
->labels
, $2);
150 merge_nodes
(target
, $4);
152 ERROR
(&@
3, "Label or path %s not found", $3);
155 | devicetree DT_REF nodedef
157 struct node
*target
= get_node_by_ref
($1, $2);
160 merge_nodes
(target
, $3);
162 ERROR
(&@
2, "Label or path %s not found", $2);
165 | devicetree DT_DEL_NODE DT_REF
';'
167 struct node
*target
= get_node_by_ref
($1, $3);
172 ERROR
(&@
3, "Label or path %s not found", $3);
180 '{' proplist subnodes
'}' ';'
182 $$
= build_node
($2, $3);
193 $$
= chain_property
($2, $1);
198 DT_PROPNODENAME
'=' propdata
';'
200 $$
= build_property
($1, $3);
202 | DT_PROPNODENAME
';'
204 $$
= build_property
($1, empty_data
);
206 | DT_DEL_PROP DT_PROPNODENAME
';'
208 $$
= build_property_delete
($2);
212 add_label
(&$2->labels
, $1);
218 propdataprefix DT_STRING
220 $$
= data_merge
($1, $2);
222 | propdataprefix arrayprefix
'>'
224 $$
= data_merge
($1, $2.data
);
226 | propdataprefix
'[' bytestring
']'
228 $$
= data_merge
($1, $3);
230 | propdataprefix DT_REF
232 $$
= data_add_marker
($1, REF_PATH
, $2);
234 | propdataprefix DT_INCBIN
'(' DT_STRING
',' integer_prim
',' integer_prim
')'
236 FILE *f
= srcfile_relative_open
($4.val
, NULL
);
240 if
(fseek
(f
, $6, SEEK_SET
) != 0)
241 die
("Couldn't seek to offset %llu in \"%s\": %s",
242 (unsigned long long)$6, $4.val
,
245 d
= data_copy_file
(f
, $8);
247 $$
= data_merge
($1, d
);
250 | propdataprefix DT_INCBIN
'(' DT_STRING
')'
252 FILE *f
= srcfile_relative_open
($4.val
, NULL
);
253 struct data d
= empty_data
;
255 d
= data_copy_file
(f
, -1);
257 $$
= data_merge
($1, d
);
262 $$
= data_add_marker
($1, LABEL
, $2);
275 | propdataprefix DT_LABEL
277 $$
= data_add_marker
($1, LABEL
, $2);
282 DT_BITS DT_LITERAL
'<'
284 unsigned long long bits
;
288 if
((bits
!= 8) && (bits
!= 16) &&
289 (bits
!= 32) && (bits
!= 64)) {
290 ERROR
(&@
2, "Array elements must be"
291 " 8, 16, 32 or 64-bits");
295 $$.data
= empty_data
;
300 $$.data
= empty_data
;
303 | arrayprefix integer_prim
306 uint64_t mask
= (1ULL << $1.bits
) - 1;
308 * Bits above mask must either be all zero
309 * (positive within range of mask) or all one
310 * (negative and sign-extended). The second
311 * condition is true if when we set all bits
312 * within the mask to one (i.e. | in the
313 * mask), all bits are one.
315 if
(($2 > mask
) && (($2 | mask
) != -1ULL))
316 ERROR
(&@
2, "Value out of range for"
317 " %d-bit array element", $1.bits
);
320 $$.data
= data_append_integer
($1.data
, $2, $1.bits
);
324 uint64_t val
= ~
0ULL >> (64 - $1.bits
);
327 $1.data
= data_add_marker
($1.data
,
331 ERROR
(&@
2, "References are only allowed in "
332 "arrays with 32-bit elements.");
334 $$.data
= data_append_integer
($1.data
, val
, $1.bits
);
336 | arrayprefix DT_LABEL
338 $$.data
= data_add_marker
($1.data
, LABEL
, $2);
345 |
'(' integer_expr
')'
357 | integer_or
'?' integer_expr
':' integer_trinary
{ $$
= $1 ?
$3 : $5; }
362 | integer_or DT_OR integer_and
{ $$
= $1 ||
$3; }
367 | integer_and DT_AND integer_bitor
{ $$
= $1 && $3; }
372 | integer_bitor
'|' integer_bitxor
{ $$
= $1 |
$3; }
377 | integer_bitxor
'^' integer_bitand
{ $$
= $1 ^
$3; }
382 | integer_bitand
'&' integer_eq
{ $$
= $1 & $3; }
387 | integer_eq DT_EQ integer_rela
{ $$
= $1 == $3; }
388 | integer_eq DT_NE integer_rela
{ $$
= $1 != $3; }
393 | integer_rela
'<' integer_shift
{ $$
= $1 < $3; }
394 | integer_rela
'>' integer_shift
{ $$
= $1 > $3; }
395 | integer_rela DT_LE integer_shift
{ $$
= $1 <= $3; }
396 | integer_rela DT_GE integer_shift
{ $$
= $1 >= $3; }
400 integer_shift DT_LSHIFT integer_add
{ $$
= $1 << $3; }
401 | integer_shift DT_RSHIFT integer_add
{ $$
= $1 >> $3; }
406 integer_add
'+' integer_mul
{ $$
= $1 + $3; }
407 | integer_add
'-' integer_mul
{ $$
= $1 - $3; }
412 integer_mul
'*' integer_unary
{ $$
= $1 * $3; }
413 | integer_mul
'/' integer_unary
418 ERROR
(&@$
, "Division by zero");
422 | integer_mul
'%' integer_unary
427 ERROR
(&@$
, "Division by zero");
436 |
'-' integer_unary
{ $$
= -$2; }
437 |
'~' integer_unary
{ $$
= ~
$2; }
438 |
'!' integer_unary
{ $$
= !$2; }
448 $$
= data_append_byte
($1, $2);
450 | bytestring DT_LABEL
452 $$
= data_add_marker
($1, LABEL
, $2);
463 $$
= chain_node
($1, $2);
467 ERROR
(&@
2, "Properties must precede subnodes");
473 DT_PROPNODENAME nodedef
475 $$
= name_node
($2, $1);
477 | DT_DEL_NODE DT_PROPNODENAME
';'
479 $$
= name_node
(build_node_delete
(), $2);
483 add_label
(&$2->labels
, $1);
490 void yyerror(char const *s
)
492 ERROR
(&yylloc, "%s", s
);