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