Rob Herring | 12869ec | 2019-06-21 08:18:32 -0600 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0-or-later |
David Gibson | a4da2e3 | 2007-12-18 15:06:42 +1100 | [diff] [blame] | 2 | /* |
| 3 | * (C) Copyright David Gibson <dwg@au1.ibm.com>, IBM Corporation. 2005. |
David Gibson | a4da2e3 | 2007-12-18 15:06:42 +1100 | [diff] [blame] | 4 | */ |
Rob Herring | 0cec114 | 2019-12-26 15:36:47 -0700 | [diff] [blame] | 5 | %locations |
| 6 | |
David Gibson | a4da2e3 | 2007-12-18 15:06:42 +1100 | [diff] [blame] | 7 | %{ |
David Gibson | ed95d74 | 2008-08-07 12:24:17 +1000 | [diff] [blame] | 8 | #include <stdio.h> |
Rob Herring | 6f05afc | 2017-01-04 10:45:20 -0600 | [diff] [blame] | 9 | #include <inttypes.h> |
David Gibson | ed95d74 | 2008-08-07 12:24:17 +1000 | [diff] [blame] | 10 | |
David Gibson | a4da2e3 | 2007-12-18 15:06:42 +1100 | [diff] [blame] | 11 | #include "dtc.h" |
| 12 | #include "srcpos.h" |
| 13 | |
David Gibson | ed95d74 | 2008-08-07 12:24:17 +1000 | [diff] [blame] | 14 | extern int yylex(void); |
John Bonesio | 658f29a | 2010-11-17 15:28:20 -0800 | [diff] [blame] | 15 | extern void yyerror(char const *s); |
Rob Herring | 4760597 | 2015-04-29 16:00:05 -0500 | [diff] [blame] | 16 | #define ERROR(loc, ...) \ |
| 17 | do { \ |
| 18 | srcpos_error((loc), "Error", __VA_ARGS__); \ |
| 19 | treesource_error = true; \ |
| 20 | } while (0) |
David Gibson | a4da2e3 | 2007-12-18 15:06:42 +1100 | [diff] [blame] | 21 | |
Rob Herring | 0cec114 | 2019-12-26 15:36:47 -0700 | [diff] [blame] | 22 | #define YYERROR_CALL(msg) yyerror(msg) |
| 23 | |
Rob Herring | 6f05afc | 2017-01-04 10:45:20 -0600 | [diff] [blame] | 24 | extern struct dt_info *parser_output; |
Rob Herring | 4760597 | 2015-04-29 16:00:05 -0500 | [diff] [blame] | 25 | extern bool treesource_error; |
David Gibson | a4da2e3 | 2007-12-18 15:06:42 +1100 | [diff] [blame] | 26 | %} |
| 27 | |
| 28 | %union { |
| 29 | char *propnodename; |
David Gibson | a4da2e3 | 2007-12-18 15:06:42 +1100 | [diff] [blame] | 30 | char *labelref; |
David Gibson | ed95d74 | 2008-08-07 12:24:17 +1000 | [diff] [blame] | 31 | uint8_t byte; |
David Gibson | a4da2e3 | 2007-12-18 15:06:42 +1100 | [diff] [blame] | 32 | struct data data; |
| 33 | |
Stephen Warren | cd29672 | 2012-09-28 21:25:59 +0000 | [diff] [blame] | 34 | struct { |
| 35 | struct data data; |
| 36 | int bits; |
| 37 | } array; |
| 38 | |
David Gibson | a4da2e3 | 2007-12-18 15:06:42 +1100 | [diff] [blame] | 39 | struct property *prop; |
| 40 | struct property *proplist; |
| 41 | struct node *node; |
| 42 | struct node *nodelist; |
| 43 | struct reserve_info *re; |
Stephen Warren | cd29672 | 2012-09-28 21:25:59 +0000 | [diff] [blame] | 44 | uint64_t integer; |
Rob Herring | 6f05afc | 2017-01-04 10:45:20 -0600 | [diff] [blame] | 45 | unsigned int flags; |
David Gibson | a4da2e3 | 2007-12-18 15:06:42 +1100 | [diff] [blame] | 46 | } |
| 47 | |
| 48 | %token DT_V1 |
Rob Herring | 6f05afc | 2017-01-04 10:45:20 -0600 | [diff] [blame] | 49 | %token DT_PLUGIN |
David Gibson | a4da2e3 | 2007-12-18 15:06:42 +1100 | [diff] [blame] | 50 | %token DT_MEMRESERVE |
Stephen Warren | cd29672 | 2012-09-28 21:25:59 +0000 | [diff] [blame] | 51 | %token DT_LSHIFT DT_RSHIFT DT_LE DT_GE DT_EQ DT_NE DT_AND DT_OR |
| 52 | %token DT_BITS |
| 53 | %token DT_DEL_PROP |
| 54 | %token DT_DEL_NODE |
Rob Herring | 50aafd6 | 2018-05-08 13:07:49 -0500 | [diff] [blame] | 55 | %token DT_OMIT_NO_REF |
David Gibson | a4da2e3 | 2007-12-18 15:06:42 +1100 | [diff] [blame] | 56 | %token <propnodename> DT_PROPNODENAME |
Rob Herring | 4760597 | 2015-04-29 16:00:05 -0500 | [diff] [blame] | 57 | %token <integer> DT_LITERAL |
| 58 | %token <integer> DT_CHAR_LITERAL |
David Gibson | a4da2e3 | 2007-12-18 15:06:42 +1100 | [diff] [blame] | 59 | %token <byte> DT_BYTE |
| 60 | %token <data> DT_STRING |
| 61 | %token <labelref> DT_LABEL |
Rob Herring | c2e7075 | 2018-11-28 18:37:35 -0600 | [diff] [blame] | 62 | %token <labelref> DT_LABEL_REF |
| 63 | %token <labelref> DT_PATH_REF |
David Gibson | ed95d74 | 2008-08-07 12:24:17 +1000 | [diff] [blame] | 64 | %token DT_INCBIN |
David Gibson | a4da2e3 | 2007-12-18 15:06:42 +1100 | [diff] [blame] | 65 | |
| 66 | %type <data> propdata |
| 67 | %type <data> propdataprefix |
Rob Herring | 6f05afc | 2017-01-04 10:45:20 -0600 | [diff] [blame] | 68 | %type <flags> header |
| 69 | %type <flags> headers |
David Gibson | a4da2e3 | 2007-12-18 15:06:42 +1100 | [diff] [blame] | 70 | %type <re> memreserve |
| 71 | %type <re> memreserves |
Stephen Warren | cd29672 | 2012-09-28 21:25:59 +0000 | [diff] [blame] | 72 | %type <array> arrayprefix |
David Gibson | a4da2e3 | 2007-12-18 15:06:42 +1100 | [diff] [blame] | 73 | %type <data> bytestring |
| 74 | %type <prop> propdef |
| 75 | %type <proplist> proplist |
Rob Herring | c2e7075 | 2018-11-28 18:37:35 -0600 | [diff] [blame] | 76 | %type <labelref> dt_ref |
David Gibson | a4da2e3 | 2007-12-18 15:06:42 +1100 | [diff] [blame] | 77 | |
| 78 | %type <node> devicetree |
| 79 | %type <node> nodedef |
| 80 | %type <node> subnode |
| 81 | %type <nodelist> subnodes |
David Gibson | a4da2e3 | 2007-12-18 15:06:42 +1100 | [diff] [blame] | 82 | |
Stephen Warren | cd29672 | 2012-09-28 21:25:59 +0000 | [diff] [blame] | 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 |
| 97 | |
David Gibson | a4da2e3 | 2007-12-18 15:06:42 +1100 | [diff] [blame] | 98 | %% |
| 99 | |
| 100 | sourcefile: |
Rob Herring | 6f05afc | 2017-01-04 10:45:20 -0600 | [diff] [blame] | 101 | headers memreserves devicetree |
David Gibson | a4da2e3 | 2007-12-18 15:06:42 +1100 | [diff] [blame] | 102 | { |
Rob Herring | 6f05afc | 2017-01-04 10:45:20 -0600 | [diff] [blame] | 103 | parser_output = build_dt_info($1, $2, $3, |
| 104 | guess_boot_cpuid($3)); |
| 105 | } |
| 106 | ; |
| 107 | |
| 108 | header: |
| 109 | DT_V1 ';' |
| 110 | { |
| 111 | $$ = DTSF_V1; |
| 112 | } |
| 113 | | DT_V1 ';' DT_PLUGIN ';' |
| 114 | { |
| 115 | $$ = DTSF_V1 | DTSF_PLUGIN; |
| 116 | } |
| 117 | ; |
| 118 | |
| 119 | headers: |
| 120 | header |
| 121 | | header headers |
| 122 | { |
| 123 | if ($2 != $1) |
| 124 | ERROR(&@2, "Header flags don't match earlier ones"); |
| 125 | $$ = $1; |
David Gibson | a4da2e3 | 2007-12-18 15:06:42 +1100 | [diff] [blame] | 126 | } |
| 127 | ; |
| 128 | |
| 129 | memreserves: |
| 130 | /* empty */ |
| 131 | { |
| 132 | $$ = NULL; |
| 133 | } |
| 134 | | memreserve memreserves |
| 135 | { |
| 136 | $$ = chain_reserve_entry($1, $2); |
| 137 | } |
| 138 | ; |
| 139 | |
| 140 | memreserve: |
Stephen Warren | cd29672 | 2012-09-28 21:25:59 +0000 | [diff] [blame] | 141 | DT_MEMRESERVE integer_prim integer_prim ';' |
David Gibson | a4da2e3 | 2007-12-18 15:06:42 +1100 | [diff] [blame] | 142 | { |
John Bonesio | 658f29a | 2010-11-17 15:28:20 -0800 | [diff] [blame] | 143 | $$ = build_reserve_entry($2, $3); |
David Gibson | a4da2e3 | 2007-12-18 15:06:42 +1100 | [diff] [blame] | 144 | } |
John Bonesio | 658f29a | 2010-11-17 15:28:20 -0800 | [diff] [blame] | 145 | | DT_LABEL memreserve |
David Gibson | a4da2e3 | 2007-12-18 15:06:42 +1100 | [diff] [blame] | 146 | { |
John Bonesio | 658f29a | 2010-11-17 15:28:20 -0800 | [diff] [blame] | 147 | add_label(&$2->labels, $1); |
| 148 | $$ = $2; |
David Gibson | a4da2e3 | 2007-12-18 15:06:42 +1100 | [diff] [blame] | 149 | } |
| 150 | ; |
| 151 | |
Rob Herring | c2e7075 | 2018-11-28 18:37:35 -0600 | [diff] [blame] | 152 | dt_ref: DT_LABEL_REF | DT_PATH_REF; |
| 153 | |
David Gibson | a4da2e3 | 2007-12-18 15:06:42 +1100 | [diff] [blame] | 154 | devicetree: |
| 155 | '/' nodedef |
| 156 | { |
John Bonesio | 658f29a | 2010-11-17 15:28:20 -0800 | [diff] [blame] | 157 | $$ = name_node($2, ""); |
| 158 | } |
| 159 | | devicetree '/' nodedef |
| 160 | { |
| 161 | $$ = merge_nodes($1, $3); |
| 162 | } |
Rob Herring | c2e7075 | 2018-11-28 18:37:35 -0600 | [diff] [blame] | 163 | | dt_ref nodedef |
Rob Herring | 9130ba8 | 2018-02-27 17:40:38 -0600 | [diff] [blame] | 164 | { |
| 165 | /* |
| 166 | * We rely on the rule being always: |
| 167 | * versioninfo plugindecl memreserves devicetree |
| 168 | * so $-1 is what we want (plugindecl) |
| 169 | */ |
| 170 | if (!($<flags>-1 & DTSF_PLUGIN)) |
| 171 | ERROR(&@2, "Label or path %s not found", $1); |
Rob Herring | c2e7075 | 2018-11-28 18:37:35 -0600 | [diff] [blame] | 172 | $$ = add_orphan_node( |
| 173 | name_node(build_node(NULL, NULL, NULL), |
| 174 | ""), |
| 175 | $2, $1); |
Rob Herring | 9130ba8 | 2018-02-27 17:40:38 -0600 | [diff] [blame] | 176 | } |
Rob Herring | c2e7075 | 2018-11-28 18:37:35 -0600 | [diff] [blame] | 177 | | devicetree DT_LABEL dt_ref nodedef |
Rob Herring | 4760597 | 2015-04-29 16:00:05 -0500 | [diff] [blame] | 178 | { |
| 179 | struct node *target = get_node_by_ref($1, $3); |
| 180 | |
Rob Herring | 89d1231 | 2017-03-21 09:01:08 -0500 | [diff] [blame] | 181 | if (target) { |
| 182 | add_label(&target->labels, $2); |
Rob Herring | 4760597 | 2015-04-29 16:00:05 -0500 | [diff] [blame] | 183 | merge_nodes(target, $4); |
Rob Herring | 89d1231 | 2017-03-21 09:01:08 -0500 | [diff] [blame] | 184 | } else |
Rob Herring | 4760597 | 2015-04-29 16:00:05 -0500 | [diff] [blame] | 185 | ERROR(&@3, "Label or path %s not found", $3); |
| 186 | $$ = $1; |
| 187 | } |
Rob Herring | c2e7075 | 2018-11-28 18:37:35 -0600 | [diff] [blame] | 188 | | devicetree DT_PATH_REF nodedef |
John Bonesio | 658f29a | 2010-11-17 15:28:20 -0800 | [diff] [blame] | 189 | { |
Rob Herring | 50aafd6 | 2018-05-08 13:07:49 -0500 | [diff] [blame] | 190 | /* |
| 191 | * We rely on the rule being always: |
| 192 | * versioninfo plugindecl memreserves devicetree |
| 193 | * so $-1 is what we want (plugindecl) |
| 194 | */ |
| 195 | if ($<flags>-1 & DTSF_PLUGIN) { |
| 196 | add_orphan_node($1, $3, $2); |
Rob Herring | 4201d05 | 2017-10-03 11:37:04 -0500 | [diff] [blame] | 197 | } else { |
Rob Herring | 50aafd6 | 2018-05-08 13:07:49 -0500 | [diff] [blame] | 198 | struct node *target = get_node_by_ref($1, $2); |
| 199 | |
| 200 | if (target) |
| 201 | merge_nodes(target, $3); |
Rob Herring | 4201d05 | 2017-10-03 11:37:04 -0500 | [diff] [blame] | 202 | else |
| 203 | ERROR(&@2, "Label or path %s not found", $2); |
| 204 | } |
John Bonesio | 658f29a | 2010-11-17 15:28:20 -0800 | [diff] [blame] | 205 | $$ = $1; |
David Gibson | a4da2e3 | 2007-12-18 15:06:42 +1100 | [diff] [blame] | 206 | } |
Rob Herring | c2e7075 | 2018-11-28 18:37:35 -0600 | [diff] [blame] | 207 | | devicetree DT_LABEL_REF nodedef |
| 208 | { |
| 209 | struct node *target = get_node_by_ref($1, $2); |
| 210 | |
| 211 | if (target) { |
| 212 | merge_nodes(target, $3); |
| 213 | } else { |
| 214 | /* |
| 215 | * We rely on the rule being always: |
| 216 | * versioninfo plugindecl memreserves devicetree |
| 217 | * so $-1 is what we want (plugindecl) |
| 218 | */ |
| 219 | if ($<flags>-1 & DTSF_PLUGIN) |
| 220 | add_orphan_node($1, $3, $2); |
| 221 | else |
| 222 | ERROR(&@2, "Label or path %s not found", $2); |
| 223 | } |
| 224 | $$ = $1; |
| 225 | } |
| 226 | | devicetree DT_DEL_NODE dt_ref ';' |
Stephen Warren | cd29672 | 2012-09-28 21:25:59 +0000 | [diff] [blame] | 227 | { |
| 228 | struct node *target = get_node_by_ref($1, $3); |
| 229 | |
Rob Herring | 4760597 | 2015-04-29 16:00:05 -0500 | [diff] [blame] | 230 | if (target) |
Stephen Warren | cd29672 | 2012-09-28 21:25:59 +0000 | [diff] [blame] | 231 | delete_node(target); |
Rob Herring | 4760597 | 2015-04-29 16:00:05 -0500 | [diff] [blame] | 232 | else |
| 233 | ERROR(&@3, "Label or path %s not found", $3); |
| 234 | |
Stephen Warren | cd29672 | 2012-09-28 21:25:59 +0000 | [diff] [blame] | 235 | |
| 236 | $$ = $1; |
| 237 | } |
Rob Herring | c2e7075 | 2018-11-28 18:37:35 -0600 | [diff] [blame] | 238 | | devicetree DT_OMIT_NO_REF dt_ref ';' |
Rob Herring | 50aafd6 | 2018-05-08 13:07:49 -0500 | [diff] [blame] | 239 | { |
| 240 | struct node *target = get_node_by_ref($1, $3); |
| 241 | |
| 242 | if (target) |
| 243 | omit_node_if_unused(target); |
| 244 | else |
| 245 | ERROR(&@3, "Label or path %s not found", $3); |
| 246 | |
| 247 | |
| 248 | $$ = $1; |
| 249 | } |
David Gibson | a4da2e3 | 2007-12-18 15:06:42 +1100 | [diff] [blame] | 250 | ; |
| 251 | |
| 252 | nodedef: |
| 253 | '{' proplist subnodes '}' ';' |
| 254 | { |
Rob Herring | c2e7075 | 2018-11-28 18:37:35 -0600 | [diff] [blame] | 255 | $$ = build_node($2, $3, &@$); |
David Gibson | a4da2e3 | 2007-12-18 15:06:42 +1100 | [diff] [blame] | 256 | } |
| 257 | ; |
| 258 | |
| 259 | proplist: |
| 260 | /* empty */ |
| 261 | { |
| 262 | $$ = NULL; |
| 263 | } |
| 264 | | proplist propdef |
| 265 | { |
| 266 | $$ = chain_property($2, $1); |
| 267 | } |
| 268 | ; |
| 269 | |
| 270 | propdef: |
John Bonesio | 658f29a | 2010-11-17 15:28:20 -0800 | [diff] [blame] | 271 | DT_PROPNODENAME '=' propdata ';' |
David Gibson | a4da2e3 | 2007-12-18 15:06:42 +1100 | [diff] [blame] | 272 | { |
Rob Herring | c2e7075 | 2018-11-28 18:37:35 -0600 | [diff] [blame] | 273 | $$ = build_property($1, $3, &@$); |
David Gibson | a4da2e3 | 2007-12-18 15:06:42 +1100 | [diff] [blame] | 274 | } |
John Bonesio | 658f29a | 2010-11-17 15:28:20 -0800 | [diff] [blame] | 275 | | DT_PROPNODENAME ';' |
David Gibson | a4da2e3 | 2007-12-18 15:06:42 +1100 | [diff] [blame] | 276 | { |
Rob Herring | c2e7075 | 2018-11-28 18:37:35 -0600 | [diff] [blame] | 277 | $$ = build_property($1, empty_data, &@$); |
John Bonesio | 658f29a | 2010-11-17 15:28:20 -0800 | [diff] [blame] | 278 | } |
Stephen Warren | cd29672 | 2012-09-28 21:25:59 +0000 | [diff] [blame] | 279 | | DT_DEL_PROP DT_PROPNODENAME ';' |
| 280 | { |
| 281 | $$ = build_property_delete($2); |
| 282 | } |
John Bonesio | 658f29a | 2010-11-17 15:28:20 -0800 | [diff] [blame] | 283 | | DT_LABEL propdef |
| 284 | { |
| 285 | add_label(&$2->labels, $1); |
| 286 | $$ = $2; |
David Gibson | a4da2e3 | 2007-12-18 15:06:42 +1100 | [diff] [blame] | 287 | } |
| 288 | ; |
| 289 | |
| 290 | propdata: |
| 291 | propdataprefix DT_STRING |
| 292 | { |
| 293 | $$ = data_merge($1, $2); |
| 294 | } |
Stephen Warren | cd29672 | 2012-09-28 21:25:59 +0000 | [diff] [blame] | 295 | | propdataprefix arrayprefix '>' |
David Gibson | a4da2e3 | 2007-12-18 15:06:42 +1100 | [diff] [blame] | 296 | { |
Stephen Warren | cd29672 | 2012-09-28 21:25:59 +0000 | [diff] [blame] | 297 | $$ = data_merge($1, $2.data); |
David Gibson | a4da2e3 | 2007-12-18 15:06:42 +1100 | [diff] [blame] | 298 | } |
| 299 | | propdataprefix '[' bytestring ']' |
| 300 | { |
| 301 | $$ = data_merge($1, $3); |
| 302 | } |
Rob Herring | c2e7075 | 2018-11-28 18:37:35 -0600 | [diff] [blame] | 303 | | propdataprefix dt_ref |
David Gibson | a4da2e3 | 2007-12-18 15:06:42 +1100 | [diff] [blame] | 304 | { |
Rob Herring | f858927 | 2018-09-13 08:59:25 -0500 | [diff] [blame] | 305 | $1 = data_add_marker($1, TYPE_STRING, $2); |
David Gibson | a4da2e3 | 2007-12-18 15:06:42 +1100 | [diff] [blame] | 306 | $$ = data_add_marker($1, REF_PATH, $2); |
| 307 | } |
Stephen Warren | cd29672 | 2012-09-28 21:25:59 +0000 | [diff] [blame] | 308 | | propdataprefix DT_INCBIN '(' DT_STRING ',' integer_prim ',' integer_prim ')' |
David Gibson | ed95d74 | 2008-08-07 12:24:17 +1000 | [diff] [blame] | 309 | { |
John Bonesio | 658f29a | 2010-11-17 15:28:20 -0800 | [diff] [blame] | 310 | FILE *f = srcfile_relative_open($4.val, NULL); |
| 311 | struct data d; |
David Gibson | ed95d74 | 2008-08-07 12:24:17 +1000 | [diff] [blame] | 312 | |
| 313 | if ($6 != 0) |
John Bonesio | 658f29a | 2010-11-17 15:28:20 -0800 | [diff] [blame] | 314 | if (fseek(f, $6, SEEK_SET) != 0) |
Rob Herring | 4760597 | 2015-04-29 16:00:05 -0500 | [diff] [blame] | 315 | die("Couldn't seek to offset %llu in \"%s\": %s", |
| 316 | (unsigned long long)$6, $4.val, |
| 317 | strerror(errno)); |
David Gibson | ed95d74 | 2008-08-07 12:24:17 +1000 | [diff] [blame] | 318 | |
John Bonesio | 658f29a | 2010-11-17 15:28:20 -0800 | [diff] [blame] | 319 | d = data_copy_file(f, $8); |
David Gibson | ed95d74 | 2008-08-07 12:24:17 +1000 | [diff] [blame] | 320 | |
| 321 | $$ = data_merge($1, d); |
John Bonesio | 658f29a | 2010-11-17 15:28:20 -0800 | [diff] [blame] | 322 | fclose(f); |
David Gibson | ed95d74 | 2008-08-07 12:24:17 +1000 | [diff] [blame] | 323 | } |
| 324 | | propdataprefix DT_INCBIN '(' DT_STRING ')' |
| 325 | { |
John Bonesio | 658f29a | 2010-11-17 15:28:20 -0800 | [diff] [blame] | 326 | FILE *f = srcfile_relative_open($4.val, NULL); |
David Gibson | ed95d74 | 2008-08-07 12:24:17 +1000 | [diff] [blame] | 327 | struct data d = empty_data; |
| 328 | |
John Bonesio | 658f29a | 2010-11-17 15:28:20 -0800 | [diff] [blame] | 329 | d = data_copy_file(f, -1); |
David Gibson | ed95d74 | 2008-08-07 12:24:17 +1000 | [diff] [blame] | 330 | |
| 331 | $$ = data_merge($1, d); |
John Bonesio | 658f29a | 2010-11-17 15:28:20 -0800 | [diff] [blame] | 332 | fclose(f); |
David Gibson | ed95d74 | 2008-08-07 12:24:17 +1000 | [diff] [blame] | 333 | } |
David Gibson | a4da2e3 | 2007-12-18 15:06:42 +1100 | [diff] [blame] | 334 | | propdata DT_LABEL |
| 335 | { |
| 336 | $$ = data_add_marker($1, LABEL, $2); |
| 337 | } |
| 338 | ; |
| 339 | |
| 340 | propdataprefix: |
| 341 | /* empty */ |
| 342 | { |
| 343 | $$ = empty_data; |
| 344 | } |
| 345 | | propdata ',' |
| 346 | { |
| 347 | $$ = $1; |
| 348 | } |
| 349 | | propdataprefix DT_LABEL |
| 350 | { |
| 351 | $$ = data_add_marker($1, LABEL, $2); |
| 352 | } |
| 353 | ; |
| 354 | |
Stephen Warren | cd29672 | 2012-09-28 21:25:59 +0000 | [diff] [blame] | 355 | arrayprefix: |
| 356 | DT_BITS DT_LITERAL '<' |
David Gibson | a4da2e3 | 2007-12-18 15:06:42 +1100 | [diff] [blame] | 357 | { |
Rob Herring | 4760597 | 2015-04-29 16:00:05 -0500 | [diff] [blame] | 358 | unsigned long long bits; |
Rob Herring | f858927 | 2018-09-13 08:59:25 -0500 | [diff] [blame] | 359 | enum markertype type = TYPE_UINT32; |
Stephen Warren | cd29672 | 2012-09-28 21:25:59 +0000 | [diff] [blame] | 360 | |
Rob Herring | 4760597 | 2015-04-29 16:00:05 -0500 | [diff] [blame] | 361 | bits = $2; |
| 362 | |
Rob Herring | f858927 | 2018-09-13 08:59:25 -0500 | [diff] [blame] | 363 | switch (bits) { |
| 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; |
| 368 | default: |
Rob Herring | 4760597 | 2015-04-29 16:00:05 -0500 | [diff] [blame] | 369 | ERROR(&@2, "Array elements must be" |
| 370 | " 8, 16, 32 or 64-bits"); |
| 371 | bits = 32; |
Stephen Warren | cd29672 | 2012-09-28 21:25:59 +0000 | [diff] [blame] | 372 | } |
Rob Herring | 4760597 | 2015-04-29 16:00:05 -0500 | [diff] [blame] | 373 | |
Rob Herring | f858927 | 2018-09-13 08:59:25 -0500 | [diff] [blame] | 374 | $$.data = data_add_marker(empty_data, type, NULL); |
Rob Herring | 4760597 | 2015-04-29 16:00:05 -0500 | [diff] [blame] | 375 | $$.bits = bits; |
David Gibson | a4da2e3 | 2007-12-18 15:06:42 +1100 | [diff] [blame] | 376 | } |
Stephen Warren | cd29672 | 2012-09-28 21:25:59 +0000 | [diff] [blame] | 377 | | '<' |
David Gibson | a4da2e3 | 2007-12-18 15:06:42 +1100 | [diff] [blame] | 378 | { |
Rob Herring | f858927 | 2018-09-13 08:59:25 -0500 | [diff] [blame] | 379 | $$.data = data_add_marker(empty_data, TYPE_UINT32, NULL); |
Stephen Warren | cd29672 | 2012-09-28 21:25:59 +0000 | [diff] [blame] | 380 | $$.bits = 32; |
David Gibson | a4da2e3 | 2007-12-18 15:06:42 +1100 | [diff] [blame] | 381 | } |
Stephen Warren | cd29672 | 2012-09-28 21:25:59 +0000 | [diff] [blame] | 382 | | arrayprefix integer_prim |
David Gibson | a4da2e3 | 2007-12-18 15:06:42 +1100 | [diff] [blame] | 383 | { |
Stephen Warren | cd29672 | 2012-09-28 21:25:59 +0000 | [diff] [blame] | 384 | if ($1.bits < 64) { |
| 385 | uint64_t mask = (1ULL << $1.bits) - 1; |
| 386 | /* |
| 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. |
| 393 | */ |
| 394 | if (($2 > mask) && (($2 | mask) != -1ULL)) |
Rob Herring | 4760597 | 2015-04-29 16:00:05 -0500 | [diff] [blame] | 395 | ERROR(&@2, "Value out of range for" |
| 396 | " %d-bit array element", $1.bits); |
Stephen Warren | cd29672 | 2012-09-28 21:25:59 +0000 | [diff] [blame] | 397 | } |
| 398 | |
| 399 | $$.data = data_append_integer($1.data, $2, $1.bits); |
David Gibson | a4da2e3 | 2007-12-18 15:06:42 +1100 | [diff] [blame] | 400 | } |
Rob Herring | c2e7075 | 2018-11-28 18:37:35 -0600 | [diff] [blame] | 401 | | arrayprefix dt_ref |
David Gibson | a4da2e3 | 2007-12-18 15:06:42 +1100 | [diff] [blame] | 402 | { |
Stephen Warren | cd29672 | 2012-09-28 21:25:59 +0000 | [diff] [blame] | 403 | uint64_t val = ~0ULL >> (64 - $1.bits); |
| 404 | |
| 405 | if ($1.bits == 32) |
| 406 | $1.data = data_add_marker($1.data, |
| 407 | REF_PHANDLE, |
| 408 | $2); |
| 409 | else |
Rob Herring | 4760597 | 2015-04-29 16:00:05 -0500 | [diff] [blame] | 410 | ERROR(&@2, "References are only allowed in " |
Stephen Warren | cd29672 | 2012-09-28 21:25:59 +0000 | [diff] [blame] | 411 | "arrays with 32-bit elements."); |
| 412 | |
| 413 | $$.data = data_append_integer($1.data, val, $1.bits); |
| 414 | } |
| 415 | | arrayprefix DT_LABEL |
| 416 | { |
| 417 | $$.data = data_add_marker($1.data, LABEL, $2); |
David Gibson | a4da2e3 | 2007-12-18 15:06:42 +1100 | [diff] [blame] | 418 | } |
| 419 | ; |
| 420 | |
Stephen Warren | cd29672 | 2012-09-28 21:25:59 +0000 | [diff] [blame] | 421 | integer_prim: |
David Gibson | a4da2e3 | 2007-12-18 15:06:42 +1100 | [diff] [blame] | 422 | DT_LITERAL |
Stephen Warren | cd29672 | 2012-09-28 21:25:59 +0000 | [diff] [blame] | 423 | | DT_CHAR_LITERAL |
Stephen Warren | cd29672 | 2012-09-28 21:25:59 +0000 | [diff] [blame] | 424 | | '(' integer_expr ')' |
| 425 | { |
| 426 | $$ = $2; |
| 427 | } |
| 428 | ; |
| 429 | |
| 430 | integer_expr: |
| 431 | integer_trinary |
| 432 | ; |
| 433 | |
| 434 | integer_trinary: |
| 435 | integer_or |
| 436 | | integer_or '?' integer_expr ':' integer_trinary { $$ = $1 ? $3 : $5; } |
| 437 | ; |
| 438 | |
| 439 | integer_or: |
| 440 | integer_and |
| 441 | | integer_or DT_OR integer_and { $$ = $1 || $3; } |
| 442 | ; |
| 443 | |
| 444 | integer_and: |
| 445 | integer_bitor |
| 446 | | integer_and DT_AND integer_bitor { $$ = $1 && $3; } |
| 447 | ; |
| 448 | |
| 449 | integer_bitor: |
| 450 | integer_bitxor |
| 451 | | integer_bitor '|' integer_bitxor { $$ = $1 | $3; } |
| 452 | ; |
| 453 | |
| 454 | integer_bitxor: |
| 455 | integer_bitand |
| 456 | | integer_bitxor '^' integer_bitand { $$ = $1 ^ $3; } |
| 457 | ; |
| 458 | |
| 459 | integer_bitand: |
| 460 | integer_eq |
| 461 | | integer_bitand '&' integer_eq { $$ = $1 & $3; } |
| 462 | ; |
| 463 | |
| 464 | integer_eq: |
| 465 | integer_rela |
| 466 | | integer_eq DT_EQ integer_rela { $$ = $1 == $3; } |
| 467 | | integer_eq DT_NE integer_rela { $$ = $1 != $3; } |
| 468 | ; |
| 469 | |
| 470 | integer_rela: |
| 471 | integer_shift |
| 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; } |
| 476 | ; |
| 477 | |
| 478 | integer_shift: |
Rob Herring | 6e9c968 | 2020-10-12 09:58:15 -0500 | [diff] [blame] | 479 | integer_shift DT_LSHIFT integer_add { $$ = ($3 < 64) ? ($1 << $3) : 0; } |
| 480 | | integer_shift DT_RSHIFT integer_add { $$ = ($3 < 64) ? ($1 >> $3) : 0; } |
Stephen Warren | cd29672 | 2012-09-28 21:25:59 +0000 | [diff] [blame] | 481 | | integer_add |
| 482 | ; |
| 483 | |
| 484 | integer_add: |
| 485 | integer_add '+' integer_mul { $$ = $1 + $3; } |
| 486 | | integer_add '-' integer_mul { $$ = $1 - $3; } |
| 487 | | integer_mul |
| 488 | ; |
| 489 | |
| 490 | integer_mul: |
| 491 | integer_mul '*' integer_unary { $$ = $1 * $3; } |
Rob Herring | 91feabc | 2016-01-26 09:04:11 -0600 | [diff] [blame] | 492 | | integer_mul '/' integer_unary |
| 493 | { |
| 494 | if ($3 != 0) { |
| 495 | $$ = $1 / $3; |
| 496 | } else { |
| 497 | ERROR(&@$, "Division by zero"); |
| 498 | $$ = 0; |
| 499 | } |
| 500 | } |
| 501 | | integer_mul '%' integer_unary |
| 502 | { |
| 503 | if ($3 != 0) { |
| 504 | $$ = $1 % $3; |
| 505 | } else { |
| 506 | ERROR(&@$, "Division by zero"); |
| 507 | $$ = 0; |
| 508 | } |
| 509 | } |
Stephen Warren | cd29672 | 2012-09-28 21:25:59 +0000 | [diff] [blame] | 510 | | integer_unary |
| 511 | ; |
| 512 | |
| 513 | integer_unary: |
| 514 | integer_prim |
| 515 | | '-' integer_unary { $$ = -$2; } |
| 516 | | '~' integer_unary { $$ = ~$2; } |
| 517 | | '!' integer_unary { $$ = !$2; } |
David Gibson | a4da2e3 | 2007-12-18 15:06:42 +1100 | [diff] [blame] | 518 | ; |
| 519 | |
| 520 | bytestring: |
| 521 | /* empty */ |
| 522 | { |
Rob Herring | f858927 | 2018-09-13 08:59:25 -0500 | [diff] [blame] | 523 | $$ = data_add_marker(empty_data, TYPE_UINT8, NULL); |
David Gibson | a4da2e3 | 2007-12-18 15:06:42 +1100 | [diff] [blame] | 524 | } |
| 525 | | bytestring DT_BYTE |
| 526 | { |
| 527 | $$ = data_append_byte($1, $2); |
| 528 | } |
| 529 | | bytestring DT_LABEL |
| 530 | { |
| 531 | $$ = data_add_marker($1, LABEL, $2); |
| 532 | } |
| 533 | ; |
| 534 | |
| 535 | subnodes: |
| 536 | /* empty */ |
| 537 | { |
| 538 | $$ = NULL; |
| 539 | } |
John Bonesio | 658f29a | 2010-11-17 15:28:20 -0800 | [diff] [blame] | 540 | | subnode subnodes |
David Gibson | a4da2e3 | 2007-12-18 15:06:42 +1100 | [diff] [blame] | 541 | { |
| 542 | $$ = chain_node($1, $2); |
| 543 | } |
| 544 | | subnode propdef |
| 545 | { |
Rob Herring | 4760597 | 2015-04-29 16:00:05 -0500 | [diff] [blame] | 546 | ERROR(&@2, "Properties must precede subnodes"); |
David Gibson | a4da2e3 | 2007-12-18 15:06:42 +1100 | [diff] [blame] | 547 | YYERROR; |
| 548 | } |
| 549 | ; |
| 550 | |
| 551 | subnode: |
John Bonesio | 658f29a | 2010-11-17 15:28:20 -0800 | [diff] [blame] | 552 | DT_PROPNODENAME nodedef |
David Gibson | a4da2e3 | 2007-12-18 15:06:42 +1100 | [diff] [blame] | 553 | { |
John Bonesio | 658f29a | 2010-11-17 15:28:20 -0800 | [diff] [blame] | 554 | $$ = name_node($2, $1); |
David Gibson | a4da2e3 | 2007-12-18 15:06:42 +1100 | [diff] [blame] | 555 | } |
Stephen Warren | cd29672 | 2012-09-28 21:25:59 +0000 | [diff] [blame] | 556 | | DT_DEL_NODE DT_PROPNODENAME ';' |
| 557 | { |
Rob Herring | c2e7075 | 2018-11-28 18:37:35 -0600 | [diff] [blame] | 558 | $$ = name_node(build_node_delete(&@$), $2); |
Stephen Warren | cd29672 | 2012-09-28 21:25:59 +0000 | [diff] [blame] | 559 | } |
Rob Herring | 50aafd6 | 2018-05-08 13:07:49 -0500 | [diff] [blame] | 560 | | DT_OMIT_NO_REF subnode |
| 561 | { |
| 562 | $$ = omit_node_if_unused($2); |
| 563 | } |
John Bonesio | 658f29a | 2010-11-17 15:28:20 -0800 | [diff] [blame] | 564 | | DT_LABEL subnode |
David Gibson | a4da2e3 | 2007-12-18 15:06:42 +1100 | [diff] [blame] | 565 | { |
John Bonesio | 658f29a | 2010-11-17 15:28:20 -0800 | [diff] [blame] | 566 | add_label(&$2->labels, $1); |
| 567 | $$ = $2; |
David Gibson | a4da2e3 | 2007-12-18 15:06:42 +1100 | [diff] [blame] | 568 | } |
| 569 | ; |
| 570 | |
| 571 | %% |
| 572 | |
Rob Herring | 4760597 | 2015-04-29 16:00:05 -0500 | [diff] [blame] | 573 | void yyerror(char const *s) |
David Gibson | a4da2e3 | 2007-12-18 15:06:42 +1100 | [diff] [blame] | 574 | { |
Rob Herring | 4760597 | 2015-04-29 16:00:05 -0500 | [diff] [blame] | 575 | ERROR(&yylloc, "%s", s); |
Stephen Warren | cd29672 | 2012-09-28 21:25:59 +0000 | [diff] [blame] | 576 | } |