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 | * |
| 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 | */ |
| 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" |
| 26 | |
| 27 | int yylex (void); |
| 28 | void yyerror (char const *); |
| 29 | |
David Gibson | f0517db | 2005-07-15 17:14:24 +1000 | [diff] [blame] | 30 | extern struct boot_info *the_boot_info; |
David Gibson | fc14dad | 2005-06-08 17:18:34 +1000 | [diff] [blame] | 31 | |
| 32 | %} |
| 33 | |
| 34 | %union { |
| 35 | cell_t cval; |
David Gibson | 03a9b9d | 2005-07-11 16:49:52 +1000 | [diff] [blame] | 36 | u8 byte; |
David Gibson | fc14dad | 2005-06-08 17:18:34 +1000 | [diff] [blame] | 37 | char *str; |
| 38 | struct data data; |
| 39 | struct property *prop; |
| 40 | struct property *proplist; |
| 41 | struct node *node; |
| 42 | struct node *nodelist; |
| 43 | int datalen; |
| 44 | int hexlen; |
David Gibson | f0517db | 2005-07-15 17:14:24 +1000 | [diff] [blame] | 45 | u64 addr; |
David Gibson | f040d95 | 2005-10-24 18:18:38 +1000 | [diff] [blame] | 46 | struct reserve_info *re; |
David Gibson | fc14dad | 2005-06-08 17:18:34 +1000 | [diff] [blame] | 47 | } |
| 48 | |
David Gibson | f0517db | 2005-07-15 17:14:24 +1000 | [diff] [blame] | 49 | %token DT_MEMRESERVE |
| 50 | %token <addr> DT_ADDR |
David Gibson | fc14dad | 2005-06-08 17:18:34 +1000 | [diff] [blame] | 51 | %token <str> DT_PROPNAME |
| 52 | %token <str> DT_NODENAME |
| 53 | %token <cval> DT_CELL |
| 54 | %token <byte> DT_BYTE |
| 55 | %token <data> DT_STRING |
| 56 | %token <str> DT_UNIT |
David Gibson | 4102d84 | 2005-06-16 14:36:37 +1000 | [diff] [blame] | 57 | %token <str> DT_LABEL |
David Gibson | 81f2e89 | 2005-06-16 17:04:00 +1000 | [diff] [blame] | 58 | %token <str> DT_REF |
David Gibson | fc14dad | 2005-06-08 17:18:34 +1000 | [diff] [blame] | 59 | |
| 60 | %type <data> propdata |
David Gibson | 32da475 | 2007-02-07 16:37:50 +1100 | [diff] [blame^] | 61 | %type <data> propdataprefix |
David Gibson | f0517db | 2005-07-15 17:14:24 +1000 | [diff] [blame] | 62 | %type <re> memreserve |
David Gibson | f040d95 | 2005-10-24 18:18:38 +1000 | [diff] [blame] | 63 | %type <re> memreserves |
David Gibson | fc14dad | 2005-06-08 17:18:34 +1000 | [diff] [blame] | 64 | %type <data> celllist |
| 65 | %type <data> bytestring |
| 66 | %type <prop> propdef |
| 67 | %type <proplist> proplist |
| 68 | |
David Gibson | f0517db | 2005-07-15 17:14:24 +1000 | [diff] [blame] | 69 | %type <node> devicetree |
David Gibson | fc14dad | 2005-06-08 17:18:34 +1000 | [diff] [blame] | 70 | %type <node> nodedef |
| 71 | %type <node> subnode |
| 72 | %type <nodelist> subnodes |
David Gibson | 4102d84 | 2005-06-16 14:36:37 +1000 | [diff] [blame] | 73 | %type <str> label |
| 74 | %type <str> nodename |
| 75 | |
David Gibson | fc14dad | 2005-06-08 17:18:34 +1000 | [diff] [blame] | 76 | %% |
| 77 | |
David Gibson | f0517db | 2005-07-15 17:14:24 +1000 | [diff] [blame] | 78 | sourcefile: memreserves devicetree { |
| 79 | the_boot_info = build_boot_info($1, $2); |
| 80 | } |
| 81 | ; |
| 82 | |
David Gibson | f040d95 | 2005-10-24 18:18:38 +1000 | [diff] [blame] | 83 | memreserves: memreserve memreserves { |
| 84 | $$ = chain_reserve_entry($1, $2); |
David Gibson | f0517db | 2005-07-15 17:14:24 +1000 | [diff] [blame] | 85 | } |
| 86 | | /* empty */ { |
David Gibson | f040d95 | 2005-10-24 18:18:38 +1000 | [diff] [blame] | 87 | $$ = NULL; |
David Gibson | f0517db | 2005-07-15 17:14:24 +1000 | [diff] [blame] | 88 | } |
| 89 | ; |
| 90 | |
| 91 | memreserve: DT_MEMRESERVE DT_ADDR DT_ADDR ';' { |
David Gibson | f040d95 | 2005-10-24 18:18:38 +1000 | [diff] [blame] | 92 | $$ = build_reserve_entry($2, $3, NULL); |
David Gibson | f0517db | 2005-07-15 17:14:24 +1000 | [diff] [blame] | 93 | } |
| 94 | | DT_MEMRESERVE DT_ADDR '-' DT_ADDR ';' { |
David Gibson | f040d95 | 2005-10-24 18:18:38 +1000 | [diff] [blame] | 95 | $$ = build_reserve_entry($2, $4 - $2 + 1, NULL); |
David Gibson | f0517db | 2005-07-15 17:14:24 +1000 | [diff] [blame] | 96 | } |
| 97 | ; |
| 98 | |
| 99 | devicetree: '/' nodedef { |
| 100 | $$ = name_node($2, "", NULL); |
| 101 | } |
David Gibson | fc14dad | 2005-06-08 17:18:34 +1000 | [diff] [blame] | 102 | ; |
| 103 | |
| 104 | nodedef: '{' proplist subnodes '}' ';' { |
| 105 | $$ = build_node($2, $3); |
| 106 | } |
| 107 | ; |
| 108 | |
| 109 | proplist: propdef proplist { |
| 110 | $$ = chain_property($1, $2); |
| 111 | } |
| 112 | | /* empty */ { |
| 113 | $$ = NULL; |
| 114 | } |
| 115 | ; |
| 116 | |
David Gibson | 4102d84 | 2005-06-16 14:36:37 +1000 | [diff] [blame] | 117 | propdef: label DT_PROPNAME '=' propdata ';' { |
| 118 | $$ = build_property($2, $4, $1); |
David Gibson | fc14dad | 2005-06-08 17:18:34 +1000 | [diff] [blame] | 119 | } |
David Gibson | 4102d84 | 2005-06-16 14:36:37 +1000 | [diff] [blame] | 120 | | label DT_PROPNAME ';' { |
David Gibson | 9ad4587 | 2005-06-17 14:32:32 +1000 | [diff] [blame] | 121 | $$ = build_property($2, empty_data, $1); |
David Gibson | fc14dad | 2005-06-08 17:18:34 +1000 | [diff] [blame] | 122 | } |
| 123 | ; |
| 124 | |
David Gibson | 32da475 | 2007-02-07 16:37:50 +1100 | [diff] [blame^] | 125 | propdata: propdataprefix DT_STRING { $$ = data_merge($1, $2); } |
| 126 | | propdataprefix '<' celllist '>' { |
| 127 | $$ = data_merge(data_append_align($1, sizeof(cell_t)), $3); |
| 128 | } |
| 129 | | propdataprefix '[' bytestring ']' { $$ = data_merge($1, $3); } |
| 130 | ; |
| 131 | |
| 132 | propdataprefix: propdata ',' { $$ = $1; } |
| 133 | | /* empty */ { $$ = empty_data; } |
David Gibson | fc14dad | 2005-06-08 17:18:34 +1000 | [diff] [blame] | 134 | ; |
| 135 | |
| 136 | celllist: celllist DT_CELL { $$ = data_append_cell($1, $2); } |
David Gibson | 81f2e89 | 2005-06-16 17:04:00 +1000 | [diff] [blame] | 137 | | celllist DT_REF { |
| 138 | $$ = data_append_cell(data_add_fixup($1, $2), -1); |
| 139 | } |
David Gibson | fc14dad | 2005-06-08 17:18:34 +1000 | [diff] [blame] | 140 | | /* empty */ { $$ = empty_data; } |
| 141 | ; |
| 142 | |
| 143 | bytestring: bytestring DT_BYTE { $$ = data_append_byte($1, $2); } |
| 144 | | /* empty */ { $$ = empty_data; } |
| 145 | ; |
| 146 | |
| 147 | subnodes: subnode subnodes { |
| 148 | $$ = chain_node($1, $2); |
| 149 | } |
| 150 | | /* empty */ { $$ = NULL; } |
| 151 | ; |
| 152 | |
David Gibson | 4102d84 | 2005-06-16 14:36:37 +1000 | [diff] [blame] | 153 | subnode: label nodename nodedef { $$ = name_node($3, $2, $1); } |
| 154 | ; |
| 155 | |
| 156 | nodename: DT_NODENAME { $$ = $1; } |
| 157 | | DT_PROPNAME { $$ = $1; } |
| 158 | ; |
| 159 | |
| 160 | label: DT_LABEL { $$ = $1; } |
| 161 | | /* empty */ { $$ = NULL; } |
David Gibson | fc14dad | 2005-06-08 17:18:34 +1000 | [diff] [blame] | 162 | ; |
| 163 | |
| 164 | %% |
| 165 | |
| 166 | void yyerror (char const *s) |
| 167 | { |
David Gibson | 86dbcbd | 2005-10-19 16:00:31 +1000 | [diff] [blame] | 168 | fprintf (stderr, "%s at line %d\n", s, yylloc.first_line); |
David Gibson | fc14dad | 2005-06-08 17:18:34 +1000 | [diff] [blame] | 169 | } |