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