blob: 16d22770c8fbb911daf53e23691d9007bbdecdf0 [file] [log] [blame]
David Gibsonfc14dad2005-06-08 17:18:34 +10001/*
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 Gibson86dbcbd2005-10-19 16:00:31 +100021%glr-parser
22%locations
23
David Gibsonfc14dad2005-06-08 17:18:34 +100024%{
25#include "dtc.h"
26
27int yylex (void);
28void yyerror (char const *);
29
David Gibsonf0517db2005-07-15 17:14:24 +100030extern struct boot_info *the_boot_info;
David Gibsonfc14dad2005-06-08 17:18:34 +100031
32%}
33
34%union {
35 cell_t cval;
David Gibson03a9b9d2005-07-11 16:49:52 +100036 u8 byte;
David Gibsonfc14dad2005-06-08 17:18:34 +100037 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 Gibsonf0517db2005-07-15 17:14:24 +100045 u64 addr;
David Gibsonf040d952005-10-24 18:18:38 +100046 struct reserve_info *re;
David Gibsonfc14dad2005-06-08 17:18:34 +100047}
48
David Gibsonf0517db2005-07-15 17:14:24 +100049%token DT_MEMRESERVE
50%token <addr> DT_ADDR
David Gibsonfc14dad2005-06-08 17:18:34 +100051%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 Gibson4102d842005-06-16 14:36:37 +100057%token <str> DT_LABEL
David Gibson81f2e892005-06-16 17:04:00 +100058%token <str> DT_REF
David Gibsonfc14dad2005-06-08 17:18:34 +100059
60%type <data> propdata
David Gibsonf0517db2005-07-15 17:14:24 +100061%type <re> memreserve
David Gibsonf040d952005-10-24 18:18:38 +100062%type <re> memreserves
David Gibsonfc14dad2005-06-08 17:18:34 +100063%type <data> celllist
64%type <data> bytestring
65%type <prop> propdef
66%type <proplist> proplist
67
David Gibsonf0517db2005-07-15 17:14:24 +100068%type <node> devicetree
David Gibsonfc14dad2005-06-08 17:18:34 +100069%type <node> nodedef
70%type <node> subnode
71%type <nodelist> subnodes
David Gibson4102d842005-06-16 14:36:37 +100072%type <str> label
73%type <str> nodename
74
David Gibsonfc14dad2005-06-08 17:18:34 +100075%%
76
David Gibsonf0517db2005-07-15 17:14:24 +100077sourcefile: memreserves devicetree {
78 the_boot_info = build_boot_info($1, $2);
79 }
80 ;
81
David Gibsonf040d952005-10-24 18:18:38 +100082memreserves: memreserve memreserves {
83 $$ = chain_reserve_entry($1, $2);
David Gibsonf0517db2005-07-15 17:14:24 +100084 }
85 | /* empty */ {
David Gibsonf040d952005-10-24 18:18:38 +100086 $$ = NULL;
David Gibsonf0517db2005-07-15 17:14:24 +100087 }
88 ;
89
90memreserve: DT_MEMRESERVE DT_ADDR DT_ADDR ';' {
David Gibsonf040d952005-10-24 18:18:38 +100091 $$ = build_reserve_entry($2, $3, NULL);
David Gibsonf0517db2005-07-15 17:14:24 +100092 }
93 | DT_MEMRESERVE DT_ADDR '-' DT_ADDR ';' {
David Gibsonf040d952005-10-24 18:18:38 +100094 $$ = build_reserve_entry($2, $4 - $2 + 1, NULL);
David Gibsonf0517db2005-07-15 17:14:24 +100095 }
96 ;
97
98devicetree: '/' nodedef {
99 $$ = name_node($2, "", NULL);
100 }
David Gibsonfc14dad2005-06-08 17:18:34 +1000101 ;
102
103nodedef: '{' proplist subnodes '}' ';' {
104 $$ = build_node($2, $3);
105 }
106 ;
107
108proplist: propdef proplist {
109 $$ = chain_property($1, $2);
110 }
111 | /* empty */ {
112 $$ = NULL;
113 }
114 ;
115
David Gibson4102d842005-06-16 14:36:37 +1000116propdef: label DT_PROPNAME '=' propdata ';' {
117 $$ = build_property($2, $4, $1);
David Gibsonfc14dad2005-06-08 17:18:34 +1000118 }
David Gibson4102d842005-06-16 14:36:37 +1000119 | label DT_PROPNAME ';' {
David Gibson9ad45872005-06-17 14:32:32 +1000120 $$ = build_property($2, empty_data, $1);
David Gibsonfc14dad2005-06-08 17:18:34 +1000121 }
122 ;
123
124propdata: DT_STRING { $$ = $1; }
125 | '<' celllist '>' { $$ = $2; }
126 | '[' bytestring ']' { $$ = $2; }
127 ;
128
129celllist: celllist DT_CELL { $$ = data_append_cell($1, $2); }
David Gibson81f2e892005-06-16 17:04:00 +1000130 | celllist DT_REF {
131 $$ = data_append_cell(data_add_fixup($1, $2), -1);
132 }
David Gibsonfc14dad2005-06-08 17:18:34 +1000133 | /* empty */ { $$ = empty_data; }
134 ;
135
136bytestring: bytestring DT_BYTE { $$ = data_append_byte($1, $2); }
137 | /* empty */ { $$ = empty_data; }
138 ;
139
140subnodes: subnode subnodes {
141 $$ = chain_node($1, $2);
142 }
143 | /* empty */ { $$ = NULL; }
144 ;
145
David Gibson4102d842005-06-16 14:36:37 +1000146subnode: label nodename nodedef { $$ = name_node($3, $2, $1); }
147 ;
148
149nodename: DT_NODENAME { $$ = $1; }
150 | DT_PROPNAME { $$ = $1; }
151 ;
152
153label: DT_LABEL { $$ = $1; }
154 | /* empty */ { $$ = NULL; }
David Gibsonfc14dad2005-06-08 17:18:34 +1000155 ;
156
157%%
158
159void yyerror (char const *s)
160{
David Gibson86dbcbd2005-10-19 16:00:31 +1000161 fprintf (stderr, "%s at line %d\n", s, yylloc.first_line);
David Gibsonfc14dad2005-06-08 17:18:34 +1000162}