gram.y revision 1.36 1 1.1 thorpej %{
2 1.36 dholland /* $NetBSD: gram.y,v 1.36 2012/03/11 21:16:08 dholland Exp $ */
3 1.1 thorpej
4 1.1 thorpej /*
5 1.1 thorpej * Copyright (c) 1992, 1993
6 1.1 thorpej * The Regents of the University of California. All rights reserved.
7 1.1 thorpej *
8 1.1 thorpej * This software was developed by the Computer Systems Engineering group
9 1.1 thorpej * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and
10 1.1 thorpej * contributed to Berkeley.
11 1.1 thorpej *
12 1.1 thorpej * All advertising materials mentioning features or use of this software
13 1.1 thorpej * must display the following acknowledgement:
14 1.1 thorpej * This product includes software developed by the University of
15 1.1 thorpej * California, Lawrence Berkeley Laboratories.
16 1.1 thorpej *
17 1.1 thorpej * Redistribution and use in source and binary forms, with or without
18 1.1 thorpej * modification, are permitted provided that the following conditions
19 1.1 thorpej * are met:
20 1.1 thorpej * 1. Redistributions of source code must retain the above copyright
21 1.1 thorpej * notice, this list of conditions and the following disclaimer.
22 1.1 thorpej * 2. Redistributions in binary form must reproduce the above copyright
23 1.1 thorpej * notice, this list of conditions and the following disclaimer in the
24 1.1 thorpej * documentation and/or other materials provided with the distribution.
25 1.1 thorpej * 3. Neither the name of the University nor the names of its contributors
26 1.1 thorpej * may be used to endorse or promote products derived from this software
27 1.1 thorpej * without specific prior written permission.
28 1.1 thorpej *
29 1.1 thorpej * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
30 1.1 thorpej * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
31 1.1 thorpej * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
32 1.1 thorpej * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
33 1.1 thorpej * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
34 1.1 thorpej * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
35 1.1 thorpej * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
36 1.1 thorpej * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
37 1.1 thorpej * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
38 1.1 thorpej * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
39 1.1 thorpej * SUCH DAMAGE.
40 1.1 thorpej *
41 1.1 thorpej * from: @(#)gram.y 8.1 (Berkeley) 6/6/93
42 1.1 thorpej */
43 1.1 thorpej
44 1.1 thorpej #include <sys/types.h>
45 1.1 thorpej #include <sys/param.h>
46 1.1 thorpej #include <ctype.h>
47 1.1 thorpej #include <stdio.h>
48 1.1 thorpej #include <stdlib.h>
49 1.1 thorpej #include <string.h>
50 1.1 thorpej #include <errno.h>
51 1.1 thorpej #include "defs.h"
52 1.1 thorpej #include "sem.h"
53 1.1 thorpej
54 1.1 thorpej #define FORMAT(n) (((n).fmt == 8 && (n).val != 0) ? "0%llo" : \
55 1.1 thorpej ((n).fmt == 16) ? "0x%llx" : "%lld")
56 1.1 thorpej
57 1.13 christos #define stop(s) cfgerror(s), exit(1)
58 1.1 thorpej
59 1.1 thorpej static struct config conf; /* at most one active at a time */
60 1.1 thorpej
61 1.31 dholland
62 1.31 dholland /*
63 1.31 dholland * Allocation wrapper functions
64 1.31 dholland */
65 1.31 dholland static void wrap_alloc(void *ptr, unsigned code);
66 1.31 dholland static void wrap_continue(void);
67 1.31 dholland static void wrap_cleanup(void);
68 1.31 dholland
69 1.31 dholland /*
70 1.31 dholland * Allocation wrapper type codes
71 1.31 dholland */
72 1.31 dholland #define WRAP_CODE_nvlist 1
73 1.36 dholland #define WRAP_CODE_loclist 2
74 1.36 dholland #define WRAP_CODE_attrlist 3
75 1.36 dholland #define WRAP_CODE_condexpr 4
76 1.31 dholland
77 1.31 dholland /*
78 1.31 dholland * The allocation wrappers themselves
79 1.31 dholland */
80 1.31 dholland #define DECL_ALLOCWRAP(t) static struct t *wrap_mk_##t(struct t *arg)
81 1.31 dholland
82 1.31 dholland DECL_ALLOCWRAP(nvlist);
83 1.36 dholland DECL_ALLOCWRAP(loclist);
84 1.32 dholland DECL_ALLOCWRAP(attrlist);
85 1.34 dholland DECL_ALLOCWRAP(condexpr);
86 1.34 dholland
87 1.34 dholland /* allow shorter names */
88 1.36 dholland #define wrap_mk_loc(p) wrap_mk_loclist(p)
89 1.34 dholland #define wrap_mk_cx(p) wrap_mk_condexpr(p)
90 1.31 dholland
91 1.31 dholland /*
92 1.31 dholland * Macros for allocating new objects
93 1.31 dholland */
94 1.31 dholland
95 1.32 dholland /* old-style for struct nvlist */
96 1.31 dholland #define new0(n,s,p,i,x) wrap_mk_nvlist(newnv(n, s, p, i, x))
97 1.1 thorpej #define new_n(n) new0(n, NULL, NULL, 0, NULL)
98 1.1 thorpej #define new_nx(n, x) new0(n, NULL, NULL, 0, x)
99 1.1 thorpej #define new_ns(n, s) new0(n, s, NULL, 0, NULL)
100 1.1 thorpej #define new_si(s, i) new0(NULL, s, NULL, i, NULL)
101 1.1 thorpej #define new_nsi(n,s,i) new0(n, s, NULL, i, NULL)
102 1.1 thorpej #define new_np(n, p) new0(n, NULL, p, 0, NULL)
103 1.1 thorpej #define new_s(s) new0(NULL, s, NULL, 0, NULL)
104 1.1 thorpej #define new_p(p) new0(NULL, NULL, p, 0, NULL)
105 1.1 thorpej #define new_px(p, x) new0(NULL, NULL, p, 0, x)
106 1.1 thorpej #define new_sx(s, x) new0(NULL, s, NULL, 0, x)
107 1.11 cube #define new_nsx(n,s,x) new0(n, s, NULL, 0, x)
108 1.24 pooka #define new_i(i) new0(NULL, NULL, NULL, i, NULL)
109 1.1 thorpej
110 1.34 dholland /* new style, type-polymorphic; ordinary and for types with multiple flavors */
111 1.32 dholland #define MK0(t) wrap_mk_##t(mk_##t())
112 1.32 dholland #define MK1(t, a0) wrap_mk_##t(mk_##t(a0))
113 1.32 dholland #define MK2(t, a0, a1) wrap_mk_##t(mk_##t(a0, a1))
114 1.36 dholland #define MK3(t, a0, a1, a2) wrap_mk_##t(mk_##t(a0, a1, a2))
115 1.32 dholland
116 1.34 dholland #define MKF0(t, f) wrap_mk_##t(mk_##t##_##f())
117 1.34 dholland #define MKF1(t, f, a0) wrap_mk_##t(mk_##t##_##f(a0))
118 1.34 dholland #define MKF2(t, f, a0, a1) wrap_mk_##t(mk_##t##_##f(a0, a1))
119 1.34 dholland
120 1.32 dholland /*
121 1.32 dholland * Data constructors
122 1.32 dholland */
123 1.32 dholland
124 1.36 dholland static struct loclist *mk_loc(const char *, const char *, long long);
125 1.36 dholland static struct loclist *mk_loc_val(const char *, struct loclist *);
126 1.32 dholland static struct attrlist *mk_attrlist(struct attrlist *, struct attr *);
127 1.34 dholland static struct condexpr *mk_cx_atom(const char *);
128 1.34 dholland static struct condexpr *mk_cx_not(struct condexpr *);
129 1.34 dholland static struct condexpr *mk_cx_and(struct condexpr *, struct condexpr *);
130 1.34 dholland static struct condexpr *mk_cx_or(struct condexpr *, struct condexpr *);
131 1.32 dholland
132 1.31 dholland /*
133 1.31 dholland * Other private functions
134 1.31 dholland */
135 1.31 dholland
136 1.20 pooka static void setmachine(const char *, const char *, struct nvlist *, int);
137 1.1 thorpej static void check_maxpart(void);
138 1.1 thorpej
139 1.36 dholland static struct loclist *present_loclist(struct loclist *ll);
140 1.36 dholland static void app(struct loclist *, struct loclist *);
141 1.36 dholland static struct loclist *locarray(const char *, int, struct loclist *, int);
142 1.36 dholland static struct loclist *namelocvals(const char *, struct loclist *);
143 1.1 thorpej
144 1.1 thorpej %}
145 1.1 thorpej
146 1.1 thorpej %union {
147 1.1 thorpej struct attr *attr;
148 1.1 thorpej struct devbase *devb;
149 1.1 thorpej struct deva *deva;
150 1.1 thorpej struct nvlist *list;
151 1.36 dholland struct loclist *loclist;
152 1.32 dholland struct attrlist *attrlist;
153 1.34 dholland struct condexpr *condexpr;
154 1.1 thorpej const char *str;
155 1.1 thorpej struct numconst num;
156 1.1 thorpej int64_t val;
157 1.1 thorpej }
158 1.1 thorpej
159 1.1 thorpej %token AND AT ATTACH
160 1.1 thorpej %token BLOCK BUILD
161 1.11 cube %token CHAR COLONEQ COMPILE_WITH CONFIG
162 1.16 drochner %token DEFFS DEFINE DEFOPT DEFPARAM DEFFLAG DEFPSEUDO DEFPSEUDODEV
163 1.16 drochner %token DEVICE DEVCLASS DUMPS DEVICE_MAJOR
164 1.1 thorpej %token ENDFILE
165 1.1 thorpej %token XFILE FILE_SYSTEM FLAGS
166 1.20 pooka %token IDENT IOCONF
167 1.24 pooka %token LINKZERO
168 1.1 thorpej %token XMACHINE MAJOR MAKEOPTIONS MAXUSERS MAXPARTITIONS MINOR
169 1.1 thorpej %token NEEDS_COUNT NEEDS_FLAG NO
170 1.6 cube %token XOBJECT OBSOLETE ON OPTIONS
171 1.22 pooka %token PACKAGE PLUSEQ PREFIX PSEUDO_DEVICE PSEUDO_ROOT
172 1.1 thorpej %token ROOT
173 1.24 pooka %token SINGLE SOURCE
174 1.1 thorpej %token TYPE
175 1.24 pooka %token VECTOR VERSION
176 1.1 thorpej %token WITH
177 1.1 thorpej %token <num> NUMBER
178 1.8 christos %token <str> PATHNAME QSTRING WORD EMPTYSTRING
179 1.1 thorpej %token ENDDEFS
180 1.1 thorpej
181 1.34 dholland %type <condexpr> fopts condexpr condatom
182 1.34 dholland %type <condexpr> cond_or_expr cond_and_expr cond_prefix_expr
183 1.34 dholland %type <condexpr> cond_base_expr
184 1.1 thorpej %type <str> fs_spec
185 1.35 dholland %type <val> fflags fflag oflags oflag
186 1.1 thorpej %type <str> rule
187 1.33 dholland %type <attr> depend
188 1.1 thorpej %type <devb> devbase
189 1.1 thorpej %type <deva> devattach_opt
190 1.36 dholland %type <list> atlist
191 1.36 dholland %type <loclist> interface_opt
192 1.1 thorpej %type <str> atname
193 1.36 dholland %type <loclist> loclist locdef
194 1.1 thorpej %type <str> locdefault
195 1.36 dholland %type <loclist> values locdefaults
196 1.33 dholland %type <attrlist> depend_list depends
197 1.36 dholland %type <loclist> locators locator
198 1.1 thorpej %type <list> dev_spec
199 1.1 thorpej %type <str> device_instance
200 1.1 thorpej %type <str> attachment
201 1.1 thorpej %type <str> value
202 1.1 thorpej %type <val> major_minor npseudo
203 1.1 thorpej %type <num> signed_number
204 1.28 dholland %type <val> device_flags
205 1.1 thorpej %type <str> deffs
206 1.1 thorpej %type <list> deffses
207 1.10 dsl %type <list> defopt
208 1.1 thorpej %type <list> defopts
209 1.35 dholland %type <str> optdepend
210 1.35 dholland %type <list> optdepends
211 1.35 dholland %type <list> optdepend_list
212 1.1 thorpej %type <str> optfile_opt
213 1.28 dholland %type <list> subarches
214 1.1 thorpej %type <str> filename stringvalue locname mkvarname
215 1.1 thorpej %type <val> device_major_block device_major_char
216 1.24 pooka %type <list> devnodes devnodetype devnodeflags devnode_dims
217 1.1 thorpej
218 1.1 thorpej %%
219 1.1 thorpej
220 1.1 thorpej /*
221 1.25 dholland * A complete configuration consists of both the configuration part (a
222 1.25 dholland * kernel config such as GENERIC or SKYNET, plus also the various
223 1.25 dholland * std.* files), which selects the material to be in the kernel, and
224 1.25 dholland * also the definition part (files, files.*, etc.) that declares what
225 1.25 dholland * material is available to be placed in kernels.
226 1.25 dholland *
227 1.25 dholland * The two parts have almost entirely separate syntaxes. This grammar
228 1.25 dholland * covers both of them. When config is run on a kernel configuration
229 1.25 dholland * file, the std.* file for the port is included explicitly. The
230 1.25 dholland * files.* files are included implicitly when the std.* file declares
231 1.25 dholland * the machine type.
232 1.25 dholland *
233 1.25 dholland * The machine spec, which brings in the definition part, must appear
234 1.25 dholland * before all configuration material except for the "topthings"; these
235 1.25 dholland * are the "source" and "build" declarations that tell config where
236 1.25 dholland * things are. These are not used by default.
237 1.25 dholland *
238 1.25 dholland * A previous version of this comment contained the following text:
239 1.25 dholland *
240 1.25 dholland * Note that we do not have sufficient keywords to enforce any
241 1.25 dholland * order between elements of "topthings" without introducing
242 1.25 dholland * shift/reduce conflicts. Instead, check order requirements in
243 1.25 dholland * the C code.
244 1.25 dholland *
245 1.25 dholland * As of March 2012 this comment makes no sense, as there are only two
246 1.25 dholland * topthings and no reason for them to be forcibly ordered.
247 1.25 dholland * Furthermore, the statement about conflicts is false.
248 1.1 thorpej */
249 1.25 dholland
250 1.25 dholland /* Complete configuration. */
251 1.28 dholland configuration:
252 1.28 dholland topthings machine_spec definition_part configuration_part
253 1.26 dholland ;
254 1.1 thorpej
255 1.25 dholland /* Sequence of zero or more topthings. */
256 1.1 thorpej topthings:
257 1.26 dholland /* empty */
258 1.26 dholland | topthings topthing
259 1.26 dholland ;
260 1.1 thorpej
261 1.25 dholland /* Directory specification. */
262 1.1 thorpej topthing:
263 1.27 dholland '\n'
264 1.27 dholland | SOURCE filename '\n' { if (!srcdir) srcdir = $2; }
265 1.26 dholland | BUILD filename '\n' { if (!builddir) builddir = $2; }
266 1.26 dholland ;
267 1.1 thorpej
268 1.25 dholland /* "machine foo" from std.whatever */
269 1.1 thorpej machine_spec:
270 1.26 dholland XMACHINE WORD '\n' { setmachine($2,NULL,NULL,0); }
271 1.28 dholland | XMACHINE WORD WORD '\n' { setmachine($2,$3,NULL,0); }
272 1.28 dholland | XMACHINE WORD WORD subarches '\n' { setmachine($2,$3,$4,0); }
273 1.26 dholland | IOCONF WORD '\n' { setmachine($2,NULL,NULL,1); }
274 1.26 dholland | error { stop("cannot proceed without machine or ioconf specifier"); }
275 1.26 dholland ;
276 1.1 thorpej
277 1.28 dholland /* One or more sub-arches. */
278 1.1 thorpej subarches:
279 1.27 dholland WORD { $$ = new_n($1); }
280 1.27 dholland | subarches WORD { $$ = new_nx($2, $1); }
281 1.26 dholland ;
282 1.1 thorpej
283 1.25 dholland /************************************************************/
284 1.25 dholland
285 1.1 thorpej /*
286 1.1 thorpej * The machine definitions grammar.
287 1.1 thorpej */
288 1.25 dholland
289 1.25 dholland /* Complete definition part: the contents of all files.* files. */
290 1.28 dholland definition_part:
291 1.28 dholland definitions ENDDEFS { check_maxpart(); check_version(); }
292 1.26 dholland ;
293 1.1 thorpej
294 1.28 dholland /* Zero or more definitions. Trap errors. */
295 1.28 dholland definitions:
296 1.28 dholland /* empty */
297 1.28 dholland | definitions '\n'
298 1.31 dholland | definitions definition '\n' { wrap_continue(); }
299 1.31 dholland | definitions error '\n' { wrap_cleanup(); }
300 1.28 dholland | definitions ENDFILE { enddefs(); checkfiles(); }
301 1.26 dholland ;
302 1.1 thorpej
303 1.25 dholland /* A single definition. */
304 1.28 dholland definition:
305 1.26 dholland file
306 1.26 dholland | object
307 1.26 dholland | device_major { do_devsw = 1; }
308 1.26 dholland | prefix
309 1.26 dholland | DEVCLASS WORD { (void)defattr($2, NULL, NULL, 1); }
310 1.35 dholland | DEFFS deffses optdepend_list { deffilesystem($2, $3); }
311 1.33 dholland | DEFINE WORD interface_opt depend_list
312 1.26 dholland { (void)defattr($2, $3, $4, 0); }
313 1.35 dholland | DEFOPT optfile_opt defopts optdepend_list
314 1.26 dholland { defoption($2, $3, $4); }
315 1.35 dholland | DEFFLAG optfile_opt defopts optdepend_list
316 1.26 dholland { defflag($2, $3, $4, 0); }
317 1.26 dholland | OBSOLETE DEFFLAG optfile_opt defopts
318 1.26 dholland { defflag($3, $4, NULL, 1); }
319 1.35 dholland | DEFPARAM optfile_opt defopts optdepend_list
320 1.26 dholland { defparam($2, $3, $4, 0); }
321 1.26 dholland | OBSOLETE DEFPARAM optfile_opt defopts
322 1.26 dholland { defparam($3, $4, NULL, 1); }
323 1.33 dholland | DEVICE devbase interface_opt depend_list
324 1.26 dholland { defdev($2, $3, $4, 0); }
325 1.33 dholland | ATTACH devbase AT atlist devattach_opt depend_list
326 1.26 dholland { defdevattach($5, $2, $4, $6); }
327 1.26 dholland | MAXPARTITIONS NUMBER { maxpartitions = $2.val; }
328 1.26 dholland | MAXUSERS NUMBER NUMBER NUMBER
329 1.26 dholland { setdefmaxusers($2.val, $3.val, $4.val); }
330 1.26 dholland | MAKEOPTIONS condmkopt_list
331 1.17 drochner /* interface_opt in DEFPSEUDO is for backwards compatibility */
332 1.33 dholland | DEFPSEUDO devbase interface_opt depend_list
333 1.26 dholland { defdev($2, $3, $4, 1); }
334 1.33 dholland | DEFPSEUDODEV devbase interface_opt depend_list
335 1.26 dholland { defdev($2, $3, $4, 2); }
336 1.26 dholland | MAJOR '{' majorlist '}'
337 1.26 dholland | VERSION NUMBER { setversion($2.val); }
338 1.26 dholland ;
339 1.1 thorpej
340 1.29 dholland /* source file: file foo/bar.c bar|baz needs-flag compile-with blah */
341 1.29 dholland file:
342 1.35 dholland XFILE filename fopts fflags rule { addfile($2, $3, $4, $5); }
343 1.26 dholland ;
344 1.1 thorpej
345 1.33 dholland /* file options: optional expression of conditions */
346 1.29 dholland fopts:
347 1.29 dholland /* empty */ { $$ = NULL; }
348 1.33 dholland | condexpr { $$ = $1; }
349 1.26 dholland ;
350 1.1 thorpej
351 1.29 dholland /* zero or more flags for a file */
352 1.35 dholland fflags:
353 1.29 dholland /* empty */ { $$ = 0; }
354 1.35 dholland | fflags fflag { $$ = $1 | $2; }
355 1.26 dholland ;
356 1.1 thorpej
357 1.29 dholland /* one flag for a file */
358 1.29 dholland fflag:
359 1.29 dholland NEEDS_COUNT { $$ = FI_NEEDSCOUNT; }
360 1.29 dholland | NEEDS_FLAG { $$ = FI_NEEDSFLAG; }
361 1.26 dholland ;
362 1.1 thorpej
363 1.29 dholland /* extra compile directive for a source file */
364 1.29 dholland rule:
365 1.26 dholland /* empty */ { $$ = NULL; }
366 1.29 dholland | COMPILE_WITH stringvalue { $$ = $2; }
367 1.29 dholland ;
368 1.29 dholland
369 1.29 dholland /* object file: object zot.o foo|zot needs-flag */
370 1.29 dholland object:
371 1.35 dholland XOBJECT filename fopts oflags { addobject($2, $3, $4); }
372 1.29 dholland ;
373 1.29 dholland
374 1.29 dholland /* zero or more flags for an object file */
375 1.35 dholland oflags:
376 1.29 dholland /* empty */ { $$ = 0; }
377 1.35 dholland | oflags oflag { $$ = $1 | $2; }
378 1.29 dholland ;
379 1.29 dholland
380 1.29 dholland /* a single flag for an object file */
381 1.29 dholland oflag:
382 1.29 dholland NEEDS_FLAG { $$ = OI_NEEDSFLAG; }
383 1.29 dholland ;
384 1.29 dholland
385 1.29 dholland /* device major declaration */
386 1.29 dholland device_major:
387 1.29 dholland DEVICE_MAJOR WORD device_major_char device_major_block fopts devnodes
388 1.29 dholland { adddevm($2, $3, $4, $5, $6); }
389 1.29 dholland ;
390 1.29 dholland
391 1.29 dholland /* char 55 */
392 1.29 dholland device_major_char:
393 1.29 dholland /* empty */ { $$ = -1; }
394 1.29 dholland | CHAR NUMBER { $$ = $2.val; }
395 1.26 dholland ;
396 1.1 thorpej
397 1.29 dholland /* block 33 */
398 1.29 dholland device_major_block:
399 1.29 dholland /* empty */ { $$ = -1; }
400 1.29 dholland | BLOCK NUMBER { $$ = $2.val; }
401 1.26 dholland ;
402 1.1 thorpej
403 1.29 dholland /* device node specification */
404 1.29 dholland devnodes:
405 1.29 dholland /* empty */ { $$ = new_s("DEVNODE_DONTBOTHER"); }
406 1.29 dholland | devnodetype ',' devnodeflags { $$ = nvcat($1, $3); }
407 1.29 dholland | devnodetype { $$ = $1; }
408 1.26 dholland ;
409 1.1 thorpej
410 1.29 dholland /* device nodes without flags */
411 1.29 dholland devnodetype:
412 1.29 dholland SINGLE { $$ = new_s("DEVNODE_SINGLE"); }
413 1.29 dholland | VECTOR '=' devnode_dims { $$ = nvcat(new_s("DEVNODE_VECTOR"), $3); }
414 1.26 dholland ;
415 1.1 thorpej
416 1.29 dholland /* dimensions (?) */
417 1.29 dholland devnode_dims:
418 1.29 dholland NUMBER { $$ = new_i($1.val); }
419 1.29 dholland | NUMBER ':' NUMBER {
420 1.29 dholland struct nvlist *__nv1, *__nv2;
421 1.26 dholland
422 1.29 dholland __nv1 = new_i($1.val);
423 1.29 dholland __nv2 = new_i($3.val);
424 1.29 dholland $$ = nvcat(__nv1, __nv2);
425 1.26 dholland }
426 1.29 dholland ;
427 1.29 dholland
428 1.29 dholland /* flags for device nodes */
429 1.29 dholland devnodeflags:
430 1.29 dholland LINKZERO { $$ = new_s("DEVNODE_FLAG_LINKZERO");}
431 1.29 dholland ;
432 1.26 dholland
433 1.29 dholland /* prefix delimiter */
434 1.29 dholland prefix:
435 1.29 dholland PREFIX filename { prefix_push($2); }
436 1.29 dholland | PREFIX { prefix_pop(); }
437 1.26 dholland ;
438 1.1 thorpej
439 1.29 dholland /* one or more file system names */
440 1.29 dholland deffses:
441 1.29 dholland deffs { $$ = new_n($1); }
442 1.29 dholland | deffses deffs { $$ = new_nx($2, $1); }
443 1.26 dholland ;
444 1.1 thorpej
445 1.29 dholland /* a single file system name */
446 1.29 dholland deffs:
447 1.29 dholland WORD { $$ = $1; }
448 1.26 dholland ;
449 1.1 thorpej
450 1.28 dholland /* optional locator specification */
451 1.1 thorpej interface_opt:
452 1.26 dholland /* empty */ { $$ = NULL; }
453 1.36 dholland | '{' '}' { $$ = present_loclist(NULL); }
454 1.36 dholland | '{' loclist '}' { $$ = present_loclist($2); }
455 1.26 dholland ;
456 1.1 thorpej
457 1.25 dholland /*
458 1.25 dholland * loclist order matters, must use right recursion
459 1.25 dholland * XXX wot?
460 1.25 dholland */
461 1.25 dholland
462 1.25 dholland /* list of locator definitions */
463 1.1 thorpej loclist:
464 1.26 dholland locdef { $$ = $1; }
465 1.26 dholland | locdef ',' loclist { $$ = $1; app($1, $3); }
466 1.26 dholland ;
467 1.1 thorpej
468 1.25 dholland /*
469 1.25 dholland * "[ WORD locdefault ]" syntax may be unnecessary...
470 1.25 dholland */
471 1.25 dholland
472 1.25 dholland /* one locator definition */
473 1.1 thorpej locdef:
474 1.36 dholland locname locdefault { $$ = MK3(loc, $1, $2, 0); }
475 1.36 dholland | locname { $$ = MK3(loc, $1, NULL, 0); }
476 1.36 dholland | '[' locname locdefault ']' { $$ = MK3(loc, $2, $3, 1); }
477 1.36 dholland | locname '[' NUMBER ']' { $$ = locarray($1, $3.val, NULL, 0); }
478 1.26 dholland | locname '[' NUMBER ']' locdefaults
479 1.36 dholland { $$ = locarray($1, $3.val, $5, 0); }
480 1.26 dholland | '[' locname '[' NUMBER ']' locdefaults ']'
481 1.36 dholland { $$ = locarray($2, $4.val, $6, 1); }
482 1.26 dholland ;
483 1.1 thorpej
484 1.25 dholland /* locator name */
485 1.1 thorpej locname:
486 1.26 dholland WORD { $$ = $1; }
487 1.26 dholland | QSTRING { $$ = $1; }
488 1.26 dholland ;
489 1.1 thorpej
490 1.25 dholland /* locator default value */
491 1.1 thorpej locdefault:
492 1.26 dholland '=' value { $$ = $2; }
493 1.26 dholland ;
494 1.1 thorpej
495 1.25 dholland /* multiple locator default values */
496 1.1 thorpej locdefaults:
497 1.26 dholland '=' '{' values '}' { $$ = $3; }
498 1.26 dholland ;
499 1.1 thorpej
500 1.33 dholland /* list of depends, may be empty */
501 1.33 dholland depend_list:
502 1.26 dholland /* empty */ { $$ = NULL; }
503 1.33 dholland | ':' depends { $$ = $2; }
504 1.29 dholland ;
505 1.29 dholland
506 1.33 dholland /* one or more depend items */
507 1.33 dholland depends:
508 1.33 dholland depend { $$ = MK2(attrlist, NULL, $1); }
509 1.33 dholland | depends ',' depend { $$ = MK2(attrlist, $1, $3); }
510 1.29 dholland ;
511 1.29 dholland
512 1.33 dholland /* one depend item (which is an attribute) */
513 1.33 dholland depend:
514 1.29 dholland WORD { $$ = getattr($1); }
515 1.29 dholland ;
516 1.29 dholland
517 1.35 dholland /* list of option depends, may be empty */
518 1.35 dholland optdepend_list:
519 1.35 dholland /* empty */ { $$ = NULL; }
520 1.35 dholland | ':' optdepends { $$ = $2; }
521 1.35 dholland ;
522 1.35 dholland
523 1.35 dholland /* a list of option dependencies */
524 1.35 dholland optdepends:
525 1.35 dholland optdepend { $$ = new_n($1); }
526 1.35 dholland | optdepends ',' optdepend { $$ = new_nx($3, $1); }
527 1.35 dholland ;
528 1.35 dholland
529 1.35 dholland /* one option depend, which is an option name */
530 1.35 dholland optdepend:
531 1.35 dholland WORD { $$ = $1; }
532 1.35 dholland ;
533 1.35 dholland
534 1.35 dholland
535 1.29 dholland /* list of places to attach: attach blah at ... */
536 1.29 dholland atlist:
537 1.29 dholland atname { $$ = new_n($1); }
538 1.29 dholland | atlist ',' atname { $$ = new_nx($3, $1); }
539 1.29 dholland ;
540 1.29 dholland
541 1.29 dholland /* a place to attach a device */
542 1.29 dholland atname:
543 1.29 dholland WORD { $$ = $1; }
544 1.29 dholland | ROOT { $$ = NULL; }
545 1.26 dholland ;
546 1.1 thorpej
547 1.29 dholland /* one or more defined options */
548 1.29 dholland defopts:
549 1.29 dholland defopt { $$ = $1; }
550 1.29 dholland | defopts defopt { $$ = nvcat($2, $1); }
551 1.26 dholland ;
552 1.1 thorpej
553 1.29 dholland /* one defined option */
554 1.29 dholland defopt:
555 1.29 dholland WORD { $$ = new_n($1); }
556 1.29 dholland | WORD '=' value { $$ = new_ns($1, $3); }
557 1.29 dholland | WORD COLONEQ value {
558 1.29 dholland struct nvlist *__nv = new_n($1);
559 1.29 dholland
560 1.29 dholland $$ = new_nsx("", $3, __nv);
561 1.29 dholland }
562 1.29 dholland | WORD '=' value COLONEQ value {
563 1.29 dholland struct nvlist *__nv = new_n($1);
564 1.26 dholland
565 1.29 dholland $$ = new_nsx("", $5, __nv);
566 1.26 dholland }
567 1.26 dholland ;
568 1.1 thorpej
569 1.29 dholland /* list of conditional makeoptions */
570 1.29 dholland condmkopt_list:
571 1.29 dholland condmkoption
572 1.29 dholland | condmkopt_list ',' condmkoption
573 1.26 dholland ;
574 1.1 thorpej
575 1.29 dholland /* one conditional make option */
576 1.29 dholland condmkoption:
577 1.33 dholland condexpr mkvarname PLUSEQ value { appendcondmkoption($1, $2, $4); }
578 1.26 dholland ;
579 1.1 thorpej
580 1.29 dholland /* device name */
581 1.29 dholland devbase:
582 1.29 dholland WORD { $$ = getdevbase($1); }
583 1.26 dholland ;
584 1.1 thorpej
585 1.29 dholland /* optional attachment: with foo */
586 1.29 dholland devattach_opt:
587 1.29 dholland /* empty */ { $$ = NULL; }
588 1.29 dholland | WITH WORD { $$ = getdevattach($2); }
589 1.26 dholland ;
590 1.1 thorpej
591 1.25 dholland /* list of major numbers */
592 1.25 dholland /* XXX why is this right-recursive? */
593 1.1 thorpej majorlist:
594 1.26 dholland majordef
595 1.26 dholland | majorlist ',' majordef
596 1.26 dholland ;
597 1.1 thorpej
598 1.25 dholland /* one major number */
599 1.1 thorpej majordef:
600 1.26 dholland devbase '=' NUMBER { setmajor($1, $3.val); }
601 1.26 dholland ;
602 1.1 thorpej
603 1.25 dholland /************************************************************/
604 1.1 thorpej
605 1.1 thorpej /*
606 1.1 thorpej * The configuration grammar.
607 1.1 thorpej */
608 1.25 dholland
609 1.25 dholland /* Complete configuration part: all std.* files plus selected config. */
610 1.28 dholland configuration_part:
611 1.28 dholland config_items
612 1.26 dholland ;
613 1.1 thorpej
614 1.28 dholland /* Zero or more config items. Trap errors. */
615 1.28 dholland config_items:
616 1.28 dholland /* empty */
617 1.28 dholland | config_items '\n'
618 1.31 dholland | config_items config_item '\n' { wrap_continue(); }
619 1.31 dholland | config_items error '\n' { wrap_cleanup(); }
620 1.26 dholland ;
621 1.1 thorpej
622 1.25 dholland /* One config item. */
623 1.28 dholland config_item:
624 1.28 dholland definition
625 1.26 dholland | NO FILE_SYSTEM no_fs_list
626 1.26 dholland | FILE_SYSTEM fs_list
627 1.26 dholland | NO MAKEOPTIONS no_mkopt_list
628 1.26 dholland | MAKEOPTIONS mkopt_list
629 1.26 dholland | NO OPTIONS no_opt_list
630 1.26 dholland | OPTIONS opt_list
631 1.26 dholland | MAXUSERS NUMBER { setmaxusers($2.val); }
632 1.26 dholland | IDENT stringvalue { setident($2); }
633 1.26 dholland | CONFIG conf root_spec sysparam_list
634 1.26 dholland { addconf(&conf); }
635 1.26 dholland | NO CONFIG WORD { delconf($3); }
636 1.26 dholland | NO PSEUDO_DEVICE WORD { delpseudo($3); }
637 1.26 dholland | PSEUDO_DEVICE WORD npseudo { addpseudo($2, $3); }
638 1.26 dholland | PSEUDO_ROOT device_instance { addpseudoroot($2); }
639 1.26 dholland | NO device_instance AT attachment
640 1.26 dholland { deldevi($2, $4); }
641 1.26 dholland | NO DEVICE AT attachment { deldeva($4); }
642 1.26 dholland | NO device_instance { deldev($2); }
643 1.28 dholland | device_instance AT attachment locators device_flags
644 1.26 dholland { adddev($1, $3, $4, $5); }
645 1.26 dholland ;
646 1.1 thorpej
647 1.25 dholland /* list of filesystems */
648 1.1 thorpej fs_list:
649 1.26 dholland fsoption
650 1.26 dholland | fs_list ',' fsoption
651 1.26 dholland ;
652 1.1 thorpej
653 1.25 dholland /* one filesystem */
654 1.1 thorpej fsoption:
655 1.26 dholland WORD { addfsoption($1); }
656 1.26 dholland ;
657 1.1 thorpej
658 1.25 dholland /* list of filesystems that had NO in front */
659 1.1 thorpej no_fs_list:
660 1.26 dholland no_fsoption
661 1.26 dholland | no_fs_list ',' no_fsoption
662 1.26 dholland ;
663 1.1 thorpej
664 1.25 dholland /* one filesystem that had NO in front */
665 1.1 thorpej no_fsoption:
666 1.26 dholland WORD { delfsoption($1); }
667 1.26 dholland ;
668 1.1 thorpej
669 1.25 dholland /* list of make options */
670 1.25 dholland /* XXX why is this right-recursive? */
671 1.1 thorpej mkopt_list:
672 1.26 dholland mkoption
673 1.26 dholland | mkopt_list ',' mkoption
674 1.26 dholland ;
675 1.1 thorpej
676 1.25 dholland /* one make option */
677 1.1 thorpej mkoption:
678 1.26 dholland mkvarname '=' value { addmkoption($1, $3); }
679 1.26 dholland | mkvarname PLUSEQ value { appendmkoption($1, $3); }
680 1.26 dholland ;
681 1.1 thorpej
682 1.25 dholland /* list of make options that had NO in front */
683 1.1 thorpej no_mkopt_list:
684 1.26 dholland no_mkoption
685 1.26 dholland | no_mkopt_list ',' no_mkoption
686 1.26 dholland ;
687 1.1 thorpej
688 1.25 dholland /* one make option that had NO in front */
689 1.29 dholland /* XXX shouldn't this be mkvarname rather than WORD? */
690 1.1 thorpej no_mkoption:
691 1.1 thorpej WORD { delmkoption($1); }
692 1.26 dholland ;
693 1.1 thorpej
694 1.25 dholland /* list of options */
695 1.1 thorpej opt_list:
696 1.26 dholland option
697 1.26 dholland | opt_list ',' option
698 1.26 dholland ;
699 1.1 thorpej
700 1.25 dholland /* one option */
701 1.1 thorpej option:
702 1.26 dholland WORD { addoption($1, NULL); }
703 1.26 dholland | WORD '=' value { addoption($1, $3); }
704 1.26 dholland ;
705 1.1 thorpej
706 1.25 dholland /* list of options that had NO in front */
707 1.1 thorpej no_opt_list:
708 1.26 dholland no_option
709 1.26 dholland | no_opt_list ',' no_option
710 1.26 dholland ;
711 1.1 thorpej
712 1.25 dholland /* one option that had NO in front */
713 1.1 thorpej no_option:
714 1.26 dholland WORD { deloption($1); }
715 1.26 dholland ;
716 1.1 thorpej
717 1.25 dholland /* the name in "config name root on ..." */
718 1.1 thorpej conf:
719 1.26 dholland WORD {
720 1.26 dholland conf.cf_name = $1;
721 1.26 dholland conf.cf_lineno = currentline();
722 1.26 dholland conf.cf_fstype = NULL;
723 1.26 dholland conf.cf_root = NULL;
724 1.26 dholland conf.cf_dump = NULL;
725 1.26 dholland }
726 1.26 dholland ;
727 1.1 thorpej
728 1.25 dholland /* root fs specification */
729 1.1 thorpej root_spec:
730 1.28 dholland ROOT on_opt dev_spec { setconf(&conf.cf_root, "root", $3); }
731 1.28 dholland | ROOT on_opt dev_spec fs_spec { setconf(&conf.cf_root, "root", $3); }
732 1.26 dholland ;
733 1.1 thorpej
734 1.29 dholland /* device for root fs or dump */
735 1.29 dholland dev_spec:
736 1.29 dholland '?' { $$ = new_si(intern("?"), NODEV); }
737 1.29 dholland | WORD { $$ = new_si($1, NODEV); }
738 1.29 dholland | major_minor { $$ = new_si(NULL, $1); }
739 1.29 dholland ;
740 1.29 dholland
741 1.29 dholland /* major and minor device number */
742 1.29 dholland major_minor:
743 1.29 dholland MAJOR NUMBER MINOR NUMBER { $$ = makedev($2.val, $4.val); }
744 1.29 dholland ;
745 1.29 dholland
746 1.25 dholland /* filesystem type for root fs specification */
747 1.1 thorpej fs_spec:
748 1.28 dholland TYPE '?' { setfstype(&conf.cf_fstype, intern("?")); }
749 1.28 dholland | TYPE WORD { setfstype(&conf.cf_fstype, $2); }
750 1.26 dholland ;
751 1.1 thorpej
752 1.25 dholland /* zero or more additional system parameters */
753 1.1 thorpej sysparam_list:
754 1.26 dholland /* empty */
755 1.26 dholland | sysparam_list sysparam
756 1.26 dholland ;
757 1.1 thorpej
758 1.25 dholland /* one additional system parameter (there's only one: dumps) */
759 1.1 thorpej sysparam:
760 1.26 dholland DUMPS on_opt dev_spec { setconf(&conf.cf_dump, "dumps", $3); }
761 1.26 dholland ;
762 1.1 thorpej
763 1.25 dholland /* number of pseudo devices to configure (which is optional) */
764 1.1 thorpej npseudo:
765 1.26 dholland /* empty */ { $$ = 1; }
766 1.26 dholland | NUMBER { $$ = $1.val; }
767 1.26 dholland ;
768 1.1 thorpej
769 1.25 dholland /* name of a device to configure */
770 1.1 thorpej device_instance:
771 1.26 dholland WORD { $$ = $1; }
772 1.26 dholland | WORD '*' { $$ = starref($1); }
773 1.26 dholland ;
774 1.1 thorpej
775 1.25 dholland /* name of a device to configure an attachment to */
776 1.1 thorpej attachment:
777 1.26 dholland ROOT { $$ = NULL; }
778 1.26 dholland | WORD { $$ = $1; }
779 1.26 dholland | WORD '?' { $$ = wildref($1); }
780 1.26 dholland ;
781 1.1 thorpej
782 1.25 dholland /* zero or more locators */
783 1.1 thorpej locators:
784 1.26 dholland /* empty */ { $$ = NULL; }
785 1.26 dholland | locators locator { $$ = $2; app($2, $1); }
786 1.26 dholland ;
787 1.1 thorpej
788 1.25 dholland /* one locator */
789 1.1 thorpej locator:
790 1.36 dholland WORD '?' { $$ = MK3(loc, $1, NULL, 0); }
791 1.36 dholland | WORD values { $$ = namelocvals($1, $2); }
792 1.26 dholland ;
793 1.1 thorpej
794 1.25 dholland /* optional device flags */
795 1.28 dholland device_flags:
796 1.26 dholland /* empty */ { $$ = 0; }
797 1.26 dholland | FLAGS NUMBER { $$ = $2.val; }
798 1.26 dholland ;
799 1.1 thorpej
800 1.29 dholland /************************************************************/
801 1.29 dholland
802 1.29 dholland /*
803 1.33 dholland * conditions
804 1.29 dholland */
805 1.29 dholland
806 1.29 dholland
807 1.29 dholland /*
808 1.29 dholland * order of options is important, must use right recursion
809 1.29 dholland *
810 1.29 dholland * dholland 20120310: wut?
811 1.29 dholland */
812 1.29 dholland
813 1.33 dholland /* expression of conditions */
814 1.33 dholland condexpr:
815 1.33 dholland cond_or_expr
816 1.30 dholland ;
817 1.30 dholland
818 1.33 dholland cond_or_expr:
819 1.33 dholland cond_and_expr
820 1.34 dholland | cond_or_expr '|' cond_and_expr { $$ = MKF2(cx, or, $1, $3); }
821 1.30 dholland ;
822 1.30 dholland
823 1.33 dholland cond_and_expr:
824 1.33 dholland cond_prefix_expr
825 1.34 dholland | cond_and_expr '&' cond_prefix_expr { $$ = MKF2(cx, and, $1, $3); }
826 1.30 dholland ;
827 1.30 dholland
828 1.33 dholland cond_prefix_expr:
829 1.33 dholland cond_base_expr
830 1.30 dholland /* XXX notyet - need to strengthen downstream first */
831 1.34 dholland /* | '!' cond_prefix_expr { $$ = MKF1(cx, not, $2); } */
832 1.30 dholland ;
833 1.30 dholland
834 1.33 dholland cond_base_expr:
835 1.33 dholland condatom { $$ = $1; }
836 1.34 dholland | '!' condatom { $$ = MKF1(cx, not, $2); }
837 1.33 dholland | '(' condexpr ')' { $$ = $2; }
838 1.29 dholland ;
839 1.29 dholland
840 1.29 dholland /* basic element of config element expression: a config element */
841 1.33 dholland condatom:
842 1.34 dholland WORD { $$ = MKF1(cx, atom, $1); }
843 1.29 dholland ;
844 1.29 dholland
845 1.29 dholland /************************************************************/
846 1.29 dholland
847 1.29 dholland /*
848 1.29 dholland * Various nonterminals shared between the grammars.
849 1.29 dholland */
850 1.29 dholland
851 1.29 dholland /* variable name for make option */
852 1.29 dholland mkvarname:
853 1.29 dholland QSTRING { $$ = $1; }
854 1.29 dholland | WORD { $$ = $1; }
855 1.29 dholland ;
856 1.29 dholland
857 1.29 dholland /* optional file for an option */
858 1.29 dholland optfile_opt:
859 1.29 dholland /* empty */ { $$ = NULL; }
860 1.29 dholland | filename { $$ = $1; }
861 1.29 dholland ;
862 1.29 dholland
863 1.29 dholland /* filename. */
864 1.29 dholland filename:
865 1.29 dholland QSTRING { $$ = $1; }
866 1.29 dholland | PATHNAME { $$ = $1; }
867 1.29 dholland ;
868 1.29 dholland
869 1.29 dholland /* constant value */
870 1.29 dholland value:
871 1.29 dholland QSTRING { $$ = $1; }
872 1.29 dholland | WORD { $$ = $1; }
873 1.29 dholland | EMPTYSTRING { $$ = $1; }
874 1.29 dholland | signed_number {
875 1.29 dholland char bf[40];
876 1.29 dholland
877 1.29 dholland (void)snprintf(bf, sizeof(bf), FORMAT($1), (long long)$1.val);
878 1.29 dholland $$ = intern(bf);
879 1.29 dholland }
880 1.29 dholland ;
881 1.29 dholland
882 1.29 dholland /* constant value that is a string */
883 1.29 dholland stringvalue:
884 1.29 dholland QSTRING { $$ = $1; }
885 1.29 dholland | WORD { $$ = $1; }
886 1.29 dholland ;
887 1.29 dholland
888 1.29 dholland /* comma-separated list of values */
889 1.29 dholland /* XXX why right-recursive? */
890 1.29 dholland values:
891 1.36 dholland value { $$ = MKF2(loc, val, $1, NULL); }
892 1.36 dholland | value ',' values { $$ = MKF2(loc, val, $1, $3); }
893 1.29 dholland ;
894 1.29 dholland
895 1.29 dholland /* possibly negative number */
896 1.29 dholland signed_number:
897 1.29 dholland NUMBER { $$ = $1; }
898 1.29 dholland | '-' NUMBER { $$.fmt = $2.fmt; $$.val = -$2.val; }
899 1.29 dholland ;
900 1.29 dholland
901 1.29 dholland /* optional ON keyword */
902 1.29 dholland on_opt:
903 1.29 dholland /* empty */
904 1.29 dholland | ON
905 1.29 dholland ;
906 1.29 dholland
907 1.1 thorpej %%
908 1.1 thorpej
909 1.1 thorpej void
910 1.1 thorpej yyerror(const char *s)
911 1.1 thorpej {
912 1.1 thorpej
913 1.13 christos cfgerror("%s", s);
914 1.1 thorpej }
915 1.1 thorpej
916 1.31 dholland /************************************************************/
917 1.31 dholland
918 1.31 dholland /*
919 1.31 dholland * Wrap allocations that live on the parser stack so that we can free
920 1.31 dholland * them again on error instead of leaking.
921 1.31 dholland */
922 1.31 dholland
923 1.31 dholland #define MAX_WRAP 1000
924 1.31 dholland
925 1.31 dholland struct wrap_entry {
926 1.31 dholland void *ptr;
927 1.31 dholland unsigned typecode;
928 1.31 dholland };
929 1.31 dholland
930 1.31 dholland static struct wrap_entry wrapstack[MAX_WRAP];
931 1.31 dholland static unsigned wrap_depth;
932 1.31 dholland
933 1.1 thorpej /*
934 1.31 dholland * Remember pointer PTR with type-code CODE.
935 1.1 thorpej */
936 1.1 thorpej static void
937 1.31 dholland wrap_alloc(void *ptr, unsigned code)
938 1.1 thorpej {
939 1.31 dholland unsigned pos;
940 1.31 dholland
941 1.31 dholland if (wrap_depth >= MAX_WRAP) {
942 1.31 dholland panic("allocation wrapper stack overflow");
943 1.31 dholland }
944 1.31 dholland pos = wrap_depth++;
945 1.31 dholland wrapstack[pos].ptr = ptr;
946 1.31 dholland wrapstack[pos].typecode = code;
947 1.31 dholland }
948 1.31 dholland
949 1.31 dholland /*
950 1.31 dholland * We succeeded; commit to keeping everything that's been allocated so
951 1.31 dholland * far and clear the stack.
952 1.31 dholland */
953 1.31 dholland static void
954 1.31 dholland wrap_continue(void)
955 1.31 dholland {
956 1.31 dholland wrap_depth = 0;
957 1.31 dholland }
958 1.31 dholland
959 1.31 dholland /*
960 1.31 dholland * We failed; destroy all the objects allocated.
961 1.31 dholland */
962 1.31 dholland static void
963 1.31 dholland wrap_cleanup(void)
964 1.31 dholland {
965 1.31 dholland unsigned i;
966 1.1 thorpej
967 1.36 dholland /*
968 1.36 dholland * Destroy each item. Note that because everything allocated
969 1.36 dholland * is entered on the list separately, lists and trees need to
970 1.36 dholland * have their links blanked before being destroyed. Also note
971 1.36 dholland * that strings are interned elsewhere and not handled by this
972 1.36 dholland * mechanism.
973 1.36 dholland */
974 1.36 dholland
975 1.31 dholland for (i=0; i<wrap_depth; i++) {
976 1.31 dholland switch (wrapstack[i].typecode) {
977 1.31 dholland case WRAP_CODE_nvlist:
978 1.31 dholland nvfree(wrapstack[i].ptr);
979 1.31 dholland break;
980 1.36 dholland case WRAP_CODE_loclist:
981 1.36 dholland {
982 1.36 dholland struct loclist *ll = wrapstack[i].ptr;
983 1.36 dholland
984 1.36 dholland ll->ll_next = NULL;
985 1.36 dholland loclist_destroy(ll);
986 1.36 dholland }
987 1.36 dholland break;
988 1.32 dholland case WRAP_CODE_attrlist:
989 1.32 dholland {
990 1.32 dholland struct attrlist *al = wrapstack[i].ptr;
991 1.32 dholland
992 1.32 dholland al->al_next = NULL;
993 1.32 dholland al->al_this = NULL;
994 1.32 dholland attrlist_destroy(al);
995 1.32 dholland }
996 1.32 dholland break;
997 1.36 dholland case WRAP_CODE_condexpr:
998 1.36 dholland {
999 1.36 dholland struct condexpr *cx = wrapstack[i].ptr;
1000 1.36 dholland
1001 1.36 dholland cx->cx_type = CX_ATOM;
1002 1.36 dholland cx->cx_atom = NULL;
1003 1.36 dholland condexpr_destroy(cx);
1004 1.36 dholland }
1005 1.36 dholland break;
1006 1.31 dholland default:
1007 1.31 dholland panic("invalid code %u on allocation wrapper stack",
1008 1.31 dholland wrapstack[i].typecode);
1009 1.31 dholland }
1010 1.31 dholland }
1011 1.32 dholland
1012 1.31 dholland wrap_depth = 0;
1013 1.1 thorpej }
1014 1.1 thorpej
1015 1.31 dholland /*
1016 1.31 dholland * Instantiate the wrapper functions.
1017 1.31 dholland *
1018 1.31 dholland * Each one calls wrap_alloc to save the pointer and then returns the
1019 1.31 dholland * pointer again; these need to be generated with the preprocessor in
1020 1.31 dholland * order to be typesafe.
1021 1.31 dholland */
1022 1.31 dholland #define DEF_ALLOCWRAP(t) \
1023 1.31 dholland static struct t * \
1024 1.31 dholland wrap_mk_##t(struct t *arg) \
1025 1.31 dholland { \
1026 1.31 dholland wrap_alloc(arg, WRAP_CODE_##t); \
1027 1.31 dholland return arg; \
1028 1.31 dholland }
1029 1.31 dholland
1030 1.31 dholland DEF_ALLOCWRAP(nvlist);
1031 1.36 dholland DEF_ALLOCWRAP(loclist);
1032 1.32 dholland DEF_ALLOCWRAP(attrlist);
1033 1.34 dholland DEF_ALLOCWRAP(condexpr);
1034 1.32 dholland
1035 1.32 dholland /************************************************************/
1036 1.32 dholland
1037 1.32 dholland /*
1038 1.32 dholland * Data constructors
1039 1.36 dholland *
1040 1.36 dholland * (These are *beneath* the allocation wrappers.)
1041 1.32 dholland */
1042 1.32 dholland
1043 1.36 dholland static struct loclist *
1044 1.36 dholland mk_loc(const char *name, const char *str, long long num)
1045 1.36 dholland {
1046 1.36 dholland return loclist_create(name, str, num);
1047 1.36 dholland }
1048 1.36 dholland
1049 1.36 dholland static struct loclist *
1050 1.36 dholland mk_loc_val(const char *str, struct loclist *next)
1051 1.36 dholland {
1052 1.36 dholland struct loclist *ll;
1053 1.36 dholland
1054 1.36 dholland ll = mk_loc(NULL, str, 0);
1055 1.36 dholland ll->ll_next = next;
1056 1.36 dholland return ll;
1057 1.36 dholland }
1058 1.36 dholland
1059 1.32 dholland static struct attrlist *
1060 1.32 dholland mk_attrlist(struct attrlist *next, struct attr *a)
1061 1.32 dholland {
1062 1.32 dholland return attrlist_cons(next, a);
1063 1.32 dholland }
1064 1.31 dholland
1065 1.34 dholland static struct condexpr *
1066 1.34 dholland mk_cx_atom(const char *s)
1067 1.34 dholland {
1068 1.34 dholland struct condexpr *cx;
1069 1.34 dholland
1070 1.34 dholland cx = condexpr_create(CX_ATOM);
1071 1.34 dholland cx->cx_atom = s;
1072 1.34 dholland return cx;
1073 1.34 dholland }
1074 1.34 dholland
1075 1.34 dholland static struct condexpr *
1076 1.34 dholland mk_cx_not(struct condexpr *sub)
1077 1.34 dholland {
1078 1.34 dholland struct condexpr *cx;
1079 1.34 dholland
1080 1.34 dholland cx = condexpr_create(CX_NOT);
1081 1.34 dholland cx->cx_not = sub;
1082 1.34 dholland return cx;
1083 1.34 dholland }
1084 1.34 dholland
1085 1.34 dholland static struct condexpr *
1086 1.34 dholland mk_cx_and(struct condexpr *left, struct condexpr *right)
1087 1.34 dholland {
1088 1.34 dholland struct condexpr *cx;
1089 1.34 dholland
1090 1.34 dholland cx = condexpr_create(CX_AND);
1091 1.34 dholland cx->cx_and.left = left;
1092 1.34 dholland cx->cx_and.right = right;
1093 1.34 dholland return cx;
1094 1.34 dholland }
1095 1.34 dholland
1096 1.34 dholland static struct condexpr *
1097 1.34 dholland mk_cx_or(struct condexpr *left, struct condexpr *right)
1098 1.34 dholland {
1099 1.34 dholland struct condexpr *cx;
1100 1.34 dholland
1101 1.34 dholland cx = condexpr_create(CX_OR);
1102 1.34 dholland cx->cx_or.left = left;
1103 1.34 dholland cx->cx_or.right = right;
1104 1.34 dholland return cx;
1105 1.34 dholland }
1106 1.34 dholland
1107 1.31 dholland /************************************************************/
1108 1.31 dholland
1109 1.1 thorpej static void
1110 1.20 pooka setmachine(const char *mch, const char *mcharch, struct nvlist *mchsubarches,
1111 1.20 pooka int isioconf)
1112 1.1 thorpej {
1113 1.1 thorpej char buf[MAXPATHLEN];
1114 1.1 thorpej struct nvlist *nv;
1115 1.1 thorpej
1116 1.20 pooka if (isioconf) {
1117 1.23 pooka fprintf(stderr, "WARNING: ioconf is an experimental feature\n");
1118 1.20 pooka if (include(_PATH_DEVNULL, ENDDEFS, 0, 0) != 0)
1119 1.20 pooka exit(1);
1120 1.20 pooka ioconfname = mch;
1121 1.20 pooka return;
1122 1.20 pooka }
1123 1.20 pooka
1124 1.1 thorpej machine = mch;
1125 1.1 thorpej machinearch = mcharch;
1126 1.1 thorpej machinesubarches = mchsubarches;
1127 1.1 thorpej
1128 1.1 thorpej /*
1129 1.14 cube * Define attributes for all the given names
1130 1.14 cube */
1131 1.15 cube if (defattr(machine, NULL, NULL, 0) != 0 ||
1132 1.15 cube (machinearch != NULL &&
1133 1.15 cube defattr(machinearch, NULL, NULL, 0) != 0))
1134 1.14 cube exit(1);
1135 1.14 cube for (nv = machinesubarches; nv != NULL; nv = nv->nv_next) {
1136 1.14 cube if (defattr(nv->nv_name, NULL, NULL, 0) != 0)
1137 1.14 cube exit(1);
1138 1.14 cube }
1139 1.14 cube
1140 1.14 cube /*
1141 1.1 thorpej * Set up the file inclusion stack. This empty include tells
1142 1.1 thorpej * the parser there are no more device definitions coming.
1143 1.1 thorpej */
1144 1.20 pooka if (include(_PATH_DEVNULL, ENDDEFS, 0, 0) != 0)
1145 1.1 thorpej exit(1);
1146 1.1 thorpej
1147 1.1 thorpej /* Include arch/${MACHINE}/conf/files.${MACHINE} */
1148 1.1 thorpej (void)snprintf(buf, sizeof(buf), "arch/%s/conf/files.%s",
1149 1.1 thorpej machine, machine);
1150 1.1 thorpej if (include(buf, ENDFILE, 0, 0) != 0)
1151 1.1 thorpej exit(1);
1152 1.1 thorpej
1153 1.1 thorpej /* Include any arch/${MACHINE_SUBARCH}/conf/files.${MACHINE_SUBARCH} */
1154 1.1 thorpej for (nv = machinesubarches; nv != NULL; nv = nv->nv_next) {
1155 1.1 thorpej (void)snprintf(buf, sizeof(buf), "arch/%s/conf/files.%s",
1156 1.1 thorpej nv->nv_name, nv->nv_name);
1157 1.1 thorpej if (include(buf, ENDFILE, 0, 0) != 0)
1158 1.1 thorpej exit(1);
1159 1.1 thorpej }
1160 1.1 thorpej
1161 1.1 thorpej /* Include any arch/${MACHINE_ARCH}/conf/files.${MACHINE_ARCH} */
1162 1.1 thorpej if (machinearch != NULL)
1163 1.1 thorpej (void)snprintf(buf, sizeof(buf), "arch/%s/conf/files.%s",
1164 1.1 thorpej machinearch, machinearch);
1165 1.1 thorpej else
1166 1.1 thorpej strlcpy(buf, _PATH_DEVNULL, sizeof(buf));
1167 1.1 thorpej if (include(buf, ENDFILE, 0, 0) != 0)
1168 1.1 thorpej exit(1);
1169 1.1 thorpej
1170 1.1 thorpej /*
1171 1.1 thorpej * Include the global conf/files. As the last thing
1172 1.1 thorpej * pushed on the stack, it will be processed first.
1173 1.1 thorpej */
1174 1.1 thorpej if (include("conf/files", ENDFILE, 0, 0) != 0)
1175 1.1 thorpej exit(1);
1176 1.2 martin
1177 1.2 martin oktopackage = 1;
1178 1.1 thorpej }
1179 1.1 thorpej
1180 1.1 thorpej static void
1181 1.1 thorpej check_maxpart(void)
1182 1.1 thorpej {
1183 1.1 thorpej
1184 1.20 pooka if (maxpartitions <= 0 && ioconfname == NULL) {
1185 1.1 thorpej stop("cannot proceed without maxpartitions specifier");
1186 1.1 thorpej }
1187 1.1 thorpej }
1188 1.1 thorpej
1189 1.1 thorpej static void
1190 1.4 cube check_version(void)
1191 1.4 cube {
1192 1.4 cube /*
1193 1.4 cube * In essence, version is 0 and is not supported anymore
1194 1.4 cube */
1195 1.4 cube if (version < CONFIG_MINVERSION)
1196 1.4 cube stop("your sources are out of date -- please update.");
1197 1.4 cube }
1198 1.4 cube
1199 1.36 dholland /*
1200 1.36 dholland * Prepend a blank entry to the locator definitions so the code in
1201 1.36 dholland * sem.c can distinguish "empty locator list" from "no locator list".
1202 1.36 dholland * XXX gross.
1203 1.36 dholland */
1204 1.36 dholland static struct loclist *
1205 1.36 dholland present_loclist(struct loclist *ll)
1206 1.36 dholland {
1207 1.36 dholland struct loclist *ret;
1208 1.36 dholland
1209 1.36 dholland ret = MK3(loc, "", NULL, 0);
1210 1.36 dholland ret->ll_next = ll;
1211 1.36 dholland return ret;
1212 1.36 dholland }
1213 1.36 dholland
1214 1.4 cube static void
1215 1.36 dholland app(struct loclist *p, struct loclist *q)
1216 1.1 thorpej {
1217 1.36 dholland while (p->ll_next)
1218 1.36 dholland p = p->ll_next;
1219 1.36 dholland p->ll_next = q;
1220 1.1 thorpej }
1221 1.1 thorpej
1222 1.36 dholland static struct loclist *
1223 1.36 dholland locarray(const char *name, int count, struct loclist *adefs, int opt)
1224 1.1 thorpej {
1225 1.36 dholland struct loclist *defs = adefs;
1226 1.36 dholland struct loclist **p;
1227 1.1 thorpej char buf[200];
1228 1.1 thorpej int i;
1229 1.1 thorpej
1230 1.1 thorpej if (count <= 0) {
1231 1.1 thorpej fprintf(stderr, "config: array with <= 0 size: %s\n", name);
1232 1.1 thorpej exit(1);
1233 1.1 thorpej }
1234 1.1 thorpej p = &defs;
1235 1.1 thorpej for(i = 0; i < count; i++) {
1236 1.1 thorpej if (*p == NULL)
1237 1.36 dholland *p = MK3(loc, NULL, "0", 0);
1238 1.1 thorpej snprintf(buf, sizeof(buf), "%s%c%d", name, ARRCHR, i);
1239 1.36 dholland (*p)->ll_name = i == 0 ? name : intern(buf);
1240 1.36 dholland (*p)->ll_num = i > 0 || opt;
1241 1.36 dholland p = &(*p)->ll_next;
1242 1.1 thorpej }
1243 1.1 thorpej *p = 0;
1244 1.1 thorpej return defs;
1245 1.1 thorpej }
1246 1.1 thorpej
1247 1.1 thorpej
1248 1.36 dholland static struct loclist *
1249 1.36 dholland namelocvals(const char *name, struct loclist *vals)
1250 1.1 thorpej {
1251 1.36 dholland struct loclist *p;
1252 1.1 thorpej char buf[200];
1253 1.1 thorpej int i;
1254 1.1 thorpej
1255 1.36 dholland for (i = 0, p = vals; p; i++, p = p->ll_next) {
1256 1.1 thorpej snprintf(buf, sizeof(buf), "%s%c%d", name, ARRCHR, i);
1257 1.36 dholland p->ll_name = i == 0 ? name : intern(buf);
1258 1.1 thorpej }
1259 1.1 thorpej return vals;
1260 1.1 thorpej }
1261 1.1 thorpej
1262