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