David Gibson | fc14dad | 2005-06-08 17:18:34 +1000 | [diff] [blame] | 1 | /* |
| 2 | * (C) Copyright David Gibson <dwg@au1.ibm.com>, IBM Corporation. 2005. |
| 3 | * |
David Gibson | 63dc9c7 | 2007-09-18 11:44:04 +1000 | [diff] [blame] | 4 | * |
David Gibson | fc14dad | 2005-06-08 17:18:34 +1000 | [diff] [blame] | 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. |
David Gibson | 63dc9c7 | 2007-09-18 11:44:04 +1000 | [diff] [blame] | 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 |
David Gibson | fc14dad | 2005-06-08 17:18:34 +1000 | [diff] [blame] | 19 | */ |
| 20 | |
David Gibson | 86dbcbd | 2005-10-19 16:00:31 +1000 | [diff] [blame] | 21 | %glr-parser |
| 22 | %locations |
| 23 | |
David Gibson | fc14dad | 2005-06-08 17:18:34 +1000 | [diff] [blame] | 24 | %{ |
| 25 | #include "dtc.h" |
Jon Loeliger | e45e6fd | 2007-03-23 15:18:41 -0500 | [diff] [blame] | 26 | #include "srcpos.h" |
David Gibson | fc14dad | 2005-06-08 17:18:34 +1000 | [diff] [blame] | 27 | |
Jon Loeliger | 3948849 | 2007-02-16 09:33:54 -0600 | [diff] [blame] | 28 | int yylex(void); |
Jon Loeliger | 3948849 | 2007-02-16 09:33:54 -0600 | [diff] [blame] | 29 | cell_t cell_from_string(char *s, unsigned int base); |
David Gibson | fc14dad | 2005-06-08 17:18:34 +1000 | [diff] [blame] | 30 | |
David Gibson | f0517db | 2005-07-15 17:14:24 +1000 | [diff] [blame] | 31 | extern struct boot_info *the_boot_info; |
David Gibson | fc14dad | 2005-06-08 17:18:34 +1000 | [diff] [blame] | 32 | |
| 33 | %} |
| 34 | |
| 35 | %union { |
| 36 | cell_t cval; |
Jon Loeliger | af0278a | 2007-02-15 10:59:27 -0600 | [diff] [blame] | 37 | unsigned int cbase; |
David Gibson | 03a9b9d | 2005-07-11 16:49:52 +1000 | [diff] [blame] | 38 | u8 byte; |
David Gibson | fc14dad | 2005-06-08 17:18:34 +1000 | [diff] [blame] | 39 | char *str; |
| 40 | struct data data; |
| 41 | struct property *prop; |
| 42 | struct property *proplist; |
| 43 | struct node *node; |
| 44 | struct node *nodelist; |
| 45 | int datalen; |
| 46 | int hexlen; |
David Gibson | f0517db | 2005-07-15 17:14:24 +1000 | [diff] [blame] | 47 | u64 addr; |
David Gibson | f040d95 | 2005-10-24 18:18:38 +1000 | [diff] [blame] | 48 | struct reserve_info *re; |
David Gibson | fc14dad | 2005-06-08 17:18:34 +1000 | [diff] [blame] | 49 | } |
| 50 | |
David Gibson | f0517db | 2005-07-15 17:14:24 +1000 | [diff] [blame] | 51 | %token DT_MEMRESERVE |
| 52 | %token <addr> DT_ADDR |
David Gibson | fc14dad | 2005-06-08 17:18:34 +1000 | [diff] [blame] | 53 | %token <str> DT_PROPNAME |
| 54 | %token <str> DT_NODENAME |
Jon Loeliger | af0278a | 2007-02-15 10:59:27 -0600 | [diff] [blame] | 55 | %token <cbase> DT_BASE |
| 56 | %token <str> DT_CELL |
David Gibson | fc14dad | 2005-06-08 17:18:34 +1000 | [diff] [blame] | 57 | %token <byte> DT_BYTE |
| 58 | %token <data> DT_STRING |
| 59 | %token <str> DT_UNIT |
David Gibson | 4102d84 | 2005-06-16 14:36:37 +1000 | [diff] [blame] | 60 | %token <str> DT_LABEL |
David Gibson | 81f2e89 | 2005-06-16 17:04:00 +1000 | [diff] [blame] | 61 | %token <str> DT_REF |
David Gibson | fc14dad | 2005-06-08 17:18:34 +1000 | [diff] [blame] | 62 | |
| 63 | %type <data> propdata |
David Gibson | 32da475 | 2007-02-07 16:37:50 +1100 | [diff] [blame] | 64 | %type <data> propdataprefix |
David Gibson | f0517db | 2005-07-15 17:14:24 +1000 | [diff] [blame] | 65 | %type <re> memreserve |
David Gibson | f040d95 | 2005-10-24 18:18:38 +1000 | [diff] [blame] | 66 | %type <re> memreserves |
Jon Loeliger | af0278a | 2007-02-15 10:59:27 -0600 | [diff] [blame] | 67 | %type <cbase> opt_cell_base |
David Gibson | fc14dad | 2005-06-08 17:18:34 +1000 | [diff] [blame] | 68 | %type <data> celllist |
| 69 | %type <data> bytestring |
| 70 | %type <prop> propdef |
| 71 | %type <proplist> proplist |
| 72 | |
David Gibson | f0517db | 2005-07-15 17:14:24 +1000 | [diff] [blame] | 73 | %type <node> devicetree |
David Gibson | fc14dad | 2005-06-08 17:18:34 +1000 | [diff] [blame] | 74 | %type <node> nodedef |
| 75 | %type <node> subnode |
| 76 | %type <nodelist> subnodes |
David Gibson | 4102d84 | 2005-06-16 14:36:37 +1000 | [diff] [blame] | 77 | %type <str> label |
| 78 | %type <str> nodename |
| 79 | |
David Gibson | fc14dad | 2005-06-08 17:18:34 +1000 | [diff] [blame] | 80 | %% |
| 81 | |
Jon Loeliger | 30807ca | 2007-10-18 09:42:16 -0500 | [diff] [blame^] | 82 | sourcefile: |
| 83 | memreserves devicetree |
| 84 | { |
David Gibson | f0517db | 2005-07-15 17:14:24 +1000 | [diff] [blame] | 85 | the_boot_info = build_boot_info($1, $2); |
| 86 | } |
| 87 | ; |
| 88 | |
Jon Loeliger | 30807ca | 2007-10-18 09:42:16 -0500 | [diff] [blame^] | 89 | memreserves: |
| 90 | memreserve memreserves |
| 91 | { |
David Gibson | f040d95 | 2005-10-24 18:18:38 +1000 | [diff] [blame] | 92 | $$ = chain_reserve_entry($1, $2); |
David Gibson | f0517db | 2005-07-15 17:14:24 +1000 | [diff] [blame] | 93 | } |
Jon Loeliger | 30807ca | 2007-10-18 09:42:16 -0500 | [diff] [blame^] | 94 | | /* empty */ |
| 95 | { |
David Gibson | f040d95 | 2005-10-24 18:18:38 +1000 | [diff] [blame] | 96 | $$ = NULL; |
David Gibson | f0517db | 2005-07-15 17:14:24 +1000 | [diff] [blame] | 97 | } |
| 98 | ; |
| 99 | |
Jon Loeliger | 30807ca | 2007-10-18 09:42:16 -0500 | [diff] [blame^] | 100 | memreserve: |
| 101 | label DT_MEMRESERVE DT_ADDR DT_ADDR ';' |
| 102 | { |
Milton Miller | d429033 | 2007-07-07 01:18:49 -0500 | [diff] [blame] | 103 | $$ = build_reserve_entry($3, $4, $1); |
David Gibson | f0517db | 2005-07-15 17:14:24 +1000 | [diff] [blame] | 104 | } |
Jon Loeliger | 30807ca | 2007-10-18 09:42:16 -0500 | [diff] [blame^] | 105 | | label DT_MEMRESERVE DT_ADDR '-' DT_ADDR ';' |
| 106 | { |
Milton Miller | d429033 | 2007-07-07 01:18:49 -0500 | [diff] [blame] | 107 | $$ = build_reserve_entry($3, $5 - $3 + 1, $1); |
David Gibson | f0517db | 2005-07-15 17:14:24 +1000 | [diff] [blame] | 108 | } |
| 109 | ; |
| 110 | |
Jon Loeliger | 30807ca | 2007-10-18 09:42:16 -0500 | [diff] [blame^] | 111 | devicetree: |
| 112 | '/' nodedef |
| 113 | { |
David Gibson | f0517db | 2005-07-15 17:14:24 +1000 | [diff] [blame] | 114 | $$ = name_node($2, "", NULL); |
| 115 | } |
David Gibson | fc14dad | 2005-06-08 17:18:34 +1000 | [diff] [blame] | 116 | ; |
| 117 | |
Jon Loeliger | 30807ca | 2007-10-18 09:42:16 -0500 | [diff] [blame^] | 118 | nodedef: |
| 119 | '{' proplist subnodes '}' ';' |
| 120 | { |
David Gibson | fc14dad | 2005-06-08 17:18:34 +1000 | [diff] [blame] | 121 | $$ = build_node($2, $3); |
| 122 | } |
| 123 | ; |
| 124 | |
Jon Loeliger | 30807ca | 2007-10-18 09:42:16 -0500 | [diff] [blame^] | 125 | proplist: |
| 126 | propdef proplist |
| 127 | { |
David Gibson | fc14dad | 2005-06-08 17:18:34 +1000 | [diff] [blame] | 128 | $$ = chain_property($1, $2); |
| 129 | } |
Jon Loeliger | 30807ca | 2007-10-18 09:42:16 -0500 | [diff] [blame^] | 130 | | /* empty */ |
| 131 | { |
David Gibson | fc14dad | 2005-06-08 17:18:34 +1000 | [diff] [blame] | 132 | $$ = NULL; |
| 133 | } |
| 134 | ; |
| 135 | |
Jon Loeliger | 30807ca | 2007-10-18 09:42:16 -0500 | [diff] [blame^] | 136 | propdef: |
| 137 | label DT_PROPNAME '=' propdata ';' |
| 138 | { |
David Gibson | 4102d84 | 2005-06-16 14:36:37 +1000 | [diff] [blame] | 139 | $$ = build_property($2, $4, $1); |
David Gibson | fc14dad | 2005-06-08 17:18:34 +1000 | [diff] [blame] | 140 | } |
Jon Loeliger | 30807ca | 2007-10-18 09:42:16 -0500 | [diff] [blame^] | 141 | | label DT_PROPNAME ';' |
| 142 | { |
David Gibson | 9ad4587 | 2005-06-17 14:32:32 +1000 | [diff] [blame] | 143 | $$ = build_property($2, empty_data, $1); |
David Gibson | fc14dad | 2005-06-08 17:18:34 +1000 | [diff] [blame] | 144 | } |
| 145 | ; |
| 146 | |
Jon Loeliger | 30807ca | 2007-10-18 09:42:16 -0500 | [diff] [blame^] | 147 | propdata: |
| 148 | propdataprefix DT_STRING |
| 149 | { |
| 150 | $$ = data_merge($1, $2); |
David Gibson | 32da475 | 2007-02-07 16:37:50 +1100 | [diff] [blame] | 151 | } |
Jon Loeliger | 30807ca | 2007-10-18 09:42:16 -0500 | [diff] [blame^] | 152 | | propdataprefix '<' celllist '>' |
| 153 | { |
| 154 | $$ = data_merge(data_append_align($1, |
| 155 | sizeof(cell_t)), $3); |
| 156 | } |
| 157 | | propdataprefix '[' bytestring ']' |
| 158 | { |
| 159 | $$ = data_merge($1, $3); |
| 160 | } |
| 161 | | propdata DT_LABEL |
| 162 | { |
| 163 | $$ = data_add_label($1, $2); |
| 164 | } |
David Gibson | 32da475 | 2007-02-07 16:37:50 +1100 | [diff] [blame] | 165 | ; |
| 166 | |
Jon Loeliger | 30807ca | 2007-10-18 09:42:16 -0500 | [diff] [blame^] | 167 | propdataprefix: |
| 168 | propdata ',' |
| 169 | { |
| 170 | $$ = $1; |
| 171 | } |
| 172 | | propdataprefix DT_LABEL |
| 173 | { |
| 174 | $$ = data_add_label($1, $2); |
| 175 | } |
| 176 | | /* empty */ |
| 177 | { |
| 178 | $$ = empty_data; |
| 179 | } |
David Gibson | fc14dad | 2005-06-08 17:18:34 +1000 | [diff] [blame] | 180 | ; |
| 181 | |
Jon Loeliger | af0278a | 2007-02-15 10:59:27 -0600 | [diff] [blame] | 182 | opt_cell_base: |
| 183 | /* empty */ |
Jon Loeliger | 30807ca | 2007-10-18 09:42:16 -0500 | [diff] [blame^] | 184 | { |
| 185 | $$ = 16; |
| 186 | } |
Jon Loeliger | af0278a | 2007-02-15 10:59:27 -0600 | [diff] [blame] | 187 | | DT_BASE |
| 188 | ; |
| 189 | |
Jon Loeliger | 30807ca | 2007-10-18 09:42:16 -0500 | [diff] [blame^] | 190 | celllist: |
| 191 | celllist opt_cell_base DT_CELL |
| 192 | { |
Jon Loeliger | af0278a | 2007-02-15 10:59:27 -0600 | [diff] [blame] | 193 | $$ = data_append_cell($1, |
Jon Loeliger | 3948849 | 2007-02-16 09:33:54 -0600 | [diff] [blame] | 194 | cell_from_string($3, $2)); |
Jon Loeliger | af0278a | 2007-02-15 10:59:27 -0600 | [diff] [blame] | 195 | } |
Jon Loeliger | 30807ca | 2007-10-18 09:42:16 -0500 | [diff] [blame^] | 196 | | celllist DT_REF |
| 197 | { |
David Gibson | 81f2e89 | 2005-06-16 17:04:00 +1000 | [diff] [blame] | 198 | $$ = data_append_cell(data_add_fixup($1, $2), -1); |
| 199 | } |
Jon Loeliger | 30807ca | 2007-10-18 09:42:16 -0500 | [diff] [blame^] | 200 | | celllist DT_LABEL |
| 201 | { |
| 202 | $$ = data_add_label($1, $2); |
| 203 | } |
| 204 | | /* empty */ |
| 205 | { |
| 206 | $$ = empty_data; |
| 207 | } |
David Gibson | fc14dad | 2005-06-08 17:18:34 +1000 | [diff] [blame] | 208 | ; |
| 209 | |
Jon Loeliger | 30807ca | 2007-10-18 09:42:16 -0500 | [diff] [blame^] | 210 | bytestring: |
| 211 | bytestring DT_BYTE |
| 212 | { |
| 213 | $$ = data_append_byte($1, $2); |
| 214 | } |
| 215 | | bytestring DT_LABEL |
| 216 | { |
| 217 | $$ = data_add_label($1, $2); |
| 218 | } |
| 219 | | /* empty */ |
| 220 | { |
| 221 | $$ = empty_data; |
| 222 | } |
David Gibson | fc14dad | 2005-06-08 17:18:34 +1000 | [diff] [blame] | 223 | ; |
| 224 | |
Jon Loeliger | 30807ca | 2007-10-18 09:42:16 -0500 | [diff] [blame^] | 225 | subnodes: |
| 226 | subnode subnodes |
| 227 | { |
David Gibson | fc14dad | 2005-06-08 17:18:34 +1000 | [diff] [blame] | 228 | $$ = chain_node($1, $2); |
| 229 | } |
Jon Loeliger | 30807ca | 2007-10-18 09:42:16 -0500 | [diff] [blame^] | 230 | | /* empty */ |
| 231 | { |
| 232 | $$ = NULL; |
| 233 | } |
David Gibson | fc14dad | 2005-06-08 17:18:34 +1000 | [diff] [blame] | 234 | ; |
| 235 | |
Jon Loeliger | 30807ca | 2007-10-18 09:42:16 -0500 | [diff] [blame^] | 236 | subnode: |
| 237 | label nodename nodedef |
| 238 | { |
| 239 | $$ = name_node($3, $2, $1); |
| 240 | } |
David Gibson | 4102d84 | 2005-06-16 14:36:37 +1000 | [diff] [blame] | 241 | ; |
| 242 | |
Jon Loeliger | 30807ca | 2007-10-18 09:42:16 -0500 | [diff] [blame^] | 243 | nodename: |
| 244 | DT_NODENAME |
| 245 | { |
| 246 | $$ = $1; |
| 247 | } |
| 248 | | DT_PROPNAME |
| 249 | { |
| 250 | $$ = $1; |
| 251 | } |
David Gibson | 4102d84 | 2005-06-16 14:36:37 +1000 | [diff] [blame] | 252 | ; |
| 253 | |
Jon Loeliger | 30807ca | 2007-10-18 09:42:16 -0500 | [diff] [blame^] | 254 | label: |
| 255 | DT_LABEL |
| 256 | { |
| 257 | $$ = $1; |
| 258 | } |
| 259 | | /* empty */ |
| 260 | { |
| 261 | $$ = NULL; |
| 262 | } |
David Gibson | fc14dad | 2005-06-08 17:18:34 +1000 | [diff] [blame] | 263 | ; |
| 264 | |
| 265 | %% |
| 266 | |
| 267 | void yyerror (char const *s) |
| 268 | { |
Jon Loeliger | e45e6fd | 2007-03-23 15:18:41 -0500 | [diff] [blame] | 269 | const char *fname = srcpos_filename_for_num(yylloc.filenum); |
| 270 | |
| 271 | if (strcmp(fname, "-") == 0) |
| 272 | fname = "stdin"; |
| 273 | |
| 274 | fprintf(stderr, "%s:%d %s\n", |
| 275 | fname, yylloc.first_line, s); |
David Gibson | fc14dad | 2005-06-08 17:18:34 +1000 | [diff] [blame] | 276 | } |
Jon Loeliger | 3948849 | 2007-02-16 09:33:54 -0600 | [diff] [blame] | 277 | |
| 278 | |
| 279 | /* |
| 280 | * Convert a string representation of a numeric cell |
| 281 | * in the given base into a cell. |
| 282 | * |
Milton Miller | 85ab5cc | 2007-07-07 01:18:48 -0500 | [diff] [blame] | 283 | * FIXME: should these specification errors be fatal instead? |
Jon Loeliger | 3948849 | 2007-02-16 09:33:54 -0600 | [diff] [blame] | 284 | */ |
| 285 | |
| 286 | cell_t cell_from_string(char *s, unsigned int base) |
| 287 | { |
| 288 | cell_t c; |
Milton Miller | 85ab5cc | 2007-07-07 01:18:48 -0500 | [diff] [blame] | 289 | char *e; |
Jon Loeliger | 3948849 | 2007-02-16 09:33:54 -0600 | [diff] [blame] | 290 | |
Milton Miller | 85ab5cc | 2007-07-07 01:18:48 -0500 | [diff] [blame] | 291 | c = strtoul(s, &e, base); |
| 292 | if (*e) { |
| 293 | fprintf(stderr, |
| 294 | "Line %d: Invalid cell value '%s' : " |
| 295 | "%c is not a base %d digit; %d assumed\n", |
| 296 | yylloc.first_line, s, *e, base, c); |
| 297 | } |
| 298 | |
Jon Loeliger | 3948849 | 2007-02-16 09:33:54 -0600 | [diff] [blame] | 299 | if (errno == EINVAL || errno == ERANGE) { |
| 300 | fprintf(stderr, |
| 301 | "Line %d: Invalid cell value '%s'; %d assumed\n", |
| 302 | yylloc.first_line, s, c); |
Milton Miller | 85ab5cc | 2007-07-07 01:18:48 -0500 | [diff] [blame] | 303 | errno = 0; |
Jon Loeliger | 3948849 | 2007-02-16 09:33:54 -0600 | [diff] [blame] | 304 | } |
| 305 | |
| 306 | return c; |
| 307 | } |