dtc-parser.y (204431) | dtc-parser.y (204433) |
---|---|
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. --- 13 unchanged lines hidden (view full) --- 22 23%{ 24#include <stdio.h> 25 26#include "dtc.h" 27#include "srcpos.h" 28 29extern int yylex(void); | 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. --- 13 unchanged lines hidden (view full) --- 22 23%{ 24#include <stdio.h> 25 26#include "dtc.h" 27#include "srcpos.h" 28 29extern int yylex(void); |
30extern void yyerror(char const *s); |
|
30 31extern struct boot_info *the_boot_info; 32extern int treesource_error; 33 34static unsigned long long eval_literal(const char *s, int base, int bits); 35%} 36 37%union { --- 12 unchanged lines hidden (view full) --- 50 struct node *nodelist; 51 struct reserve_info *re; 52} 53 54%token DT_V1 55%token DT_MEMRESERVE 56%token <propnodename> DT_PROPNODENAME 57%token <literal> DT_LITERAL | 31 32extern struct boot_info *the_boot_info; 33extern int treesource_error; 34 35static unsigned long long eval_literal(const char *s, int base, int bits); 36%} 37 38%union { --- 12 unchanged lines hidden (view full) --- 51 struct node *nodelist; 52 struct reserve_info *re; 53} 54 55%token DT_V1 56%token DT_MEMRESERVE 57%token <propnodename> DT_PROPNODENAME 58%token <literal> DT_LITERAL |
58%token <literal> DT_LEGACYLITERAL | |
59%token <cbase> DT_BASE 60%token <byte> DT_BYTE 61%token <data> DT_STRING 62%token <labelref> DT_LABEL 63%token <labelref> DT_REF 64%token DT_INCBIN 65 66%type <data> propdata 67%type <data> propdataprefix 68%type <re> memreserve 69%type <re> memreserves | 59%token <cbase> DT_BASE 60%token <byte> DT_BYTE 61%token <data> DT_STRING 62%token <labelref> DT_LABEL 63%token <labelref> DT_REF 64%token DT_INCBIN 65 66%type <data> propdata 67%type <data> propdataprefix 68%type <re> memreserve 69%type <re> memreserves |
70%type <re> v0_memreserve 71%type <re> v0_memreserves | |
72%type <addr> addr 73%type <data> celllist | 70%type <addr> addr 71%type <data> celllist |
74%type <cbase> cellbase | |
75%type <cell> cellval 76%type <data> bytestring 77%type <prop> propdef 78%type <proplist> proplist 79 80%type <node> devicetree 81%type <node> nodedef 82%type <node> subnode 83%type <nodelist> subnodes 84%type <labelref> label 85 86%% 87 88sourcefile: 89 DT_V1 ';' memreserves devicetree 90 { 91 the_boot_info = build_boot_info($3, $4, 0); 92 } | 72%type <cell> cellval 73%type <data> bytestring 74%type <prop> propdef 75%type <proplist> proplist 76 77%type <node> devicetree 78%type <node> nodedef 79%type <node> subnode 80%type <nodelist> subnodes 81%type <labelref> label 82 83%% 84 85sourcefile: 86 DT_V1 ';' memreserves devicetree 87 { 88 the_boot_info = build_boot_info($3, $4, 0); 89 } |
93 | v0_memreserves devicetree 94 { 95 the_boot_info = build_boot_info($1, $2, 0); 96 } | |
97 ; 98 99memreserves: 100 /* empty */ 101 { 102 $$ = NULL; 103 } 104 | memreserve memreserves --- 4 unchanged lines hidden (view full) --- 109 110memreserve: 111 label DT_MEMRESERVE addr addr ';' 112 { 113 $$ = build_reserve_entry($3, $4, $1); 114 } 115 ; 116 | 90 ; 91 92memreserves: 93 /* empty */ 94 { 95 $$ = NULL; 96 } 97 | memreserve memreserves --- 4 unchanged lines hidden (view full) --- 102 103memreserve: 104 label DT_MEMRESERVE addr addr ';' 105 { 106 $$ = build_reserve_entry($3, $4, $1); 107 } 108 ; 109 |
117v0_memreserves: 118 /* empty */ 119 { 120 $$ = NULL; 121 } 122 | v0_memreserve v0_memreserves 123 { 124 $$ = chain_reserve_entry($1, $2); 125 }; 126 ; 127 128v0_memreserve: 129 memreserve 130 { 131 $$ = $1; 132 } 133 | label DT_MEMRESERVE addr '-' addr ';' 134 { 135 $$ = build_reserve_entry($3, $5 - $3 + 1, $1); 136 } 137 ; 138 | |
139addr: 140 DT_LITERAL 141 { 142 $$ = eval_literal($1, 0, 64); 143 } | 110addr: 111 DT_LITERAL 112 { 113 $$ = eval_literal($1, 0, 64); 114 } |
144 | DT_LEGACYLITERAL 145 { 146 $$ = eval_literal($1, 16, 64); 147 } | |
148 ; 149 150devicetree: 151 '/' nodedef 152 { 153 $$ = name_node($2, "", NULL); 154 } 155 ; --- 47 unchanged lines hidden (view full) --- 203 | propdataprefix DT_INCBIN '(' DT_STRING ',' addr ',' addr ')' 204 { 205 struct search_path path = { srcpos_file->dir, NULL, NULL }; 206 struct dtc_file *file = dtc_open_file($4.val, &path); 207 struct data d = empty_data; 208 209 if ($6 != 0) 210 if (fseek(file->file, $6, SEEK_SET) != 0) | 115 ; 116 117devicetree: 118 '/' nodedef 119 { 120 $$ = name_node($2, "", NULL); 121 } 122 ; --- 47 unchanged lines hidden (view full) --- 170 | propdataprefix DT_INCBIN '(' DT_STRING ',' addr ',' addr ')' 171 { 172 struct search_path path = { srcpos_file->dir, NULL, NULL }; 173 struct dtc_file *file = dtc_open_file($4.val, &path); 174 struct data d = empty_data; 175 176 if ($6 != 0) 177 if (fseek(file->file, $6, SEEK_SET) != 0) |
211 yyerrorf("Couldn't seek to offset %llu in \"%s\": %s", 212 (unsigned long long)$6, 213 $4.val, strerror(errno)); | 178 srcpos_error(&yylloc, 179 "Couldn't seek to offset %llu in \"%s\": %s", 180 (unsigned long long)$6, 181 $4.val, 182 strerror(errno)); |
214 215 d = data_copy_file(file->file, $8); 216 217 $$ = data_merge($1, d); 218 dtc_close_file(file); 219 } 220 | propdataprefix DT_INCBIN '(' DT_STRING ')' 221 { --- 42 unchanged lines hidden (view full) --- 264 $2), -1); 265 } 266 | celllist DT_LABEL 267 { 268 $$ = data_add_marker($1, LABEL, $2); 269 } 270 ; 271 | 183 184 d = data_copy_file(file->file, $8); 185 186 $$ = data_merge($1, d); 187 dtc_close_file(file); 188 } 189 | propdataprefix DT_INCBIN '(' DT_STRING ')' 190 { --- 42 unchanged lines hidden (view full) --- 233 $2), -1); 234 } 235 | celllist DT_LABEL 236 { 237 $$ = data_add_marker($1, LABEL, $2); 238 } 239 ; 240 |
272cellbase: 273 /* empty */ 274 { 275 $$ = 16; 276 } 277 | DT_BASE 278 ; 279 | |
280cellval: 281 DT_LITERAL 282 { 283 $$ = eval_literal($1, 0, 32); 284 } | 241cellval: 242 DT_LITERAL 243 { 244 $$ = eval_literal($1, 0, 32); 245 } |
285 | cellbase DT_LEGACYLITERAL 286 { 287 $$ = eval_literal($2, $1, 32); 288 } | |
289 ; 290 291bytestring: 292 /* empty */ 293 { 294 $$ = empty_data; 295 } 296 | bytestring DT_BYTE --- 37 unchanged lines hidden (view full) --- 334 | DT_LABEL 335 { 336 $$ = $1; 337 } 338 ; 339 340%% 341 | 246 ; 247 248bytestring: 249 /* empty */ 250 { 251 $$ = empty_data; 252 } 253 | bytestring DT_BYTE --- 37 unchanged lines hidden (view full) --- 291 | DT_LABEL 292 { 293 $$ = $1; 294 } 295 ; 296 297%% 298 |
342void yyerrorf(char const *s, ...) | 299void yyerror(char const *s) |
343{ | 300{ |
344 const char *fname = srcpos_file ? srcpos_file->name : "<no-file>"; 345 va_list va; 346 va_start(va, s); 347 348 if (strcmp(fname, "-") == 0) 349 fname = "stdin"; 350 351 fprintf(stderr, "%s:%d ", fname, yylloc.first_line); 352 vfprintf(stderr, s, va); 353 fprintf(stderr, "\n"); 354 | 301 srcpos_error(&yylloc, "%s", s); |
355 treesource_error = 1; | 302 treesource_error = 1; |
356 va_end(va); | |
357} 358 | 303} 304 |
359void yyerror (char const *s) 360{ 361 yyerrorf("%s", s); 362} 363 | |
364static unsigned long long eval_literal(const char *s, int base, int bits) 365{ 366 unsigned long long val; 367 char *e; 368 369 errno = 0; 370 val = strtoull(s, &e, base); 371 if (*e) 372 yyerror("bad characters in literal"); 373 else if ((errno == ERANGE) 374 || ((bits < 64) && (val >= (1ULL << bits)))) 375 yyerror("literal out of range"); 376 else if (errno != 0) 377 yyerror("bad literal"); 378 return val; 379} | 305static unsigned long long eval_literal(const char *s, int base, int bits) 306{ 307 unsigned long long val; 308 char *e; 309 310 errno = 0; 311 val = strtoull(s, &e, base); 312 if (*e) 313 yyerror("bad characters in literal"); 314 else if ((errno == ERANGE) 315 || ((bits < 64) && (val >= (1ULL << bits)))) 316 yyerror("literal out of range"); 317 else if (errno != 0) 318 yyerror("bad literal"); 319 return val; 320} |