xref: /openbsd/usr.sbin/config/config.h (revision db3296cf)
1 /*	$OpenBSD: config.h,v 1.19 2003/06/02 23:36:52 millert Exp $	*/
2 /*	$NetBSD: config.h,v 1.30 1997/02/02 21:12:30 thorpej 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: @(#)config.h	8.1 (Berkeley) 6/6/93
42  */
43 
44 /*
45  * config.h:  Global definitions for "config"
46  */
47 
48 #include <sys/types.h>
49 #include <sys/param.h>
50 
51 #if !defined(MAKE_BOOTSTRAP) && defined(BSD)
52 #include <sys/cdefs.h>
53 #include <paths.h>
54 #endif /* ...BSD */
55 
56 #include <stdlib.h>
57 #include <unistd.h>
58 
59 /* These are really for MAKE_BOOTSTRAP but harmless. */
60 #ifndef __dead
61 #define __dead
62 #endif
63 #ifndef _PATH_DEVNULL
64 #define _PATH_DEVNULL "/dev/null"
65 #endif
66 
67 
68 /*
69  * Name/value lists.  Values can be strings or pointers and/or can carry
70  * integers.  The names can be NULL, resulting in simple value lists.
71  */
72 struct nvlist {
73 	struct	nvlist *nv_next;
74 	const char *nv_name;
75 	union {
76 		const char *un_str;
77 		void *un_ptr;
78 	} nv_un;
79 #define	nv_str	nv_un.un_str
80 #define	nv_ptr	nv_un.un_ptr
81 	int	nv_int;
82 };
83 
84 /*
85  * Kernel configurations.
86  */
87 struct config {
88 	struct	config *cf_next;	/* linked list */
89 	const char *cf_name;		/* "vmunix" */
90 	int	cf_lineno;		/* source line */
91 	struct	nvlist *cf_root;	/* "root on ra0a" */
92 	struct	nvlist *cf_swap;	/* "swap on ra0b and ra1b" */
93 	struct	nvlist *cf_dump;	/* "dumps on ra0b" */
94 };
95 
96 /*
97  * Attributes.  These come in two flavors: "plain" and "interface".
98  * Plain attributes (e.g., "ether") simply serve to pull in files.
99  * Interface attributes (e.g., "scsi") carry three lists: locators,
100  * child devices, and references.  The locators are those things
101  * that must be specified in order to configure a device instance
102  * using this attribute (e.g., "tg0 at scsi0").  The a_devs field
103  * lists child devices that can connect here (e.g., "tg"s), while
104  * the a_refs are parents that carry the attribute (e.g., actual
105  * SCSI host adapter drivers such as the SPARC "esp").
106  */
107 struct attr {
108 	const char *a_name;		/* name of this attribute */
109 	int	a_iattr;		/* true => allows children */
110 	struct	nvlist *a_locs;		/* locators required */
111 	int	a_loclen;		/* length of above list */
112 	struct	nvlist *a_devs;		/* children */
113 	struct	nvlist *a_refs;		/* parents */
114 };
115 
116 /*
117  * The "base" part (struct devbase) of a device ("uba", "sd"; but not
118  * "uba2" or "sd0").  It may be found "at" one or more attributes,
119  * including "at root" (this is represented by a NULL attribute), as
120  * specified by the device attachments (struct deva).
121  *
122  * Each device may also export attributes.  If any provide an output
123  * interface (e.g., "esp" provides "scsi"), other devices (e.g.,
124  * "tg"s) can be found at instances of this one (e.g., "esp"s).
125  * Such a connection must provide locators as specified by that
126  * interface attribute (e.g., "target").  The base device can
127  * export both output (aka `interface') attributes, as well as
128  * import input (`plain') attributes.  Device attachments may
129  * only import input attributes; it makes no sense to have a
130  * specific attachment export a new interface to other devices.
131  *
132  * Each base carries a list of instances (via d_ihead).  Note that this
133  * list "skips over" aliases; those must be found through the instances
134  * themselves.  Each base also carries a list of possible attachments,
135  * each of which specify a set of devices that the device can attach
136  * to, as well as the device instances that are actually using that
137  * attachment.
138  */
139 struct devbase {
140 	const char *d_name;		/* e.g., "sd" */
141 	struct	devbase *d_next;	/* linked list */
142 	int	d_isdef;		/* set once properly defined */
143 	int	d_ispseudo;		/* is a pseudo-device */
144 	int	d_major;		/* used for "root on sd0", e.g. */
145 	struct	nvlist *d_attrs;	/* attributes, if any */
146 	int	d_umax;			/* highest unit number + 1 */
147 	struct	devi *d_ihead;		/* first instance, if any */
148 	struct	devi **d_ipp;		/* used for tacking on more instances */
149 	struct	deva *d_ahead;		/* first attachment, if any */
150 	struct	deva **d_app;		/* used for tacking on attachments */
151 };
152 
153 struct deva {
154 	const char *d_name;		/* name of attachment, e.g. "com_isa" */
155 	struct	deva *d_next;		/* linked list */
156 	struct	deva *d_bsame;		/* list on same base */
157 	int	d_isdef;		/* set once properly defined */
158 	struct	devbase *d_devbase;	/* the base device */
159 	struct	nvlist *d_atlist;	/* e.g., "at tg" (attr list) */
160 	struct	nvlist *d_attrs;	/* attributes, if any */
161 	struct	devi *d_ihead;		/* first instance, if any */
162 	struct	devi **d_ipp;		/* used for tacking on more instances */
163 };
164 
165 /*
166  * An "instance" of a device.  The same instance may be listed more
167  * than once, e.g., "xx0 at isa? port FOO" + "xx0 at isa? port BAR".
168  *
169  * After everything has been read in and verified, the devi's are
170  * "packed" to collect all the information needed to generate ioconf.c.
171  * In particular, we try to collapse multiple aliases into a single entry.
172  * We then assign each "primary" (non-collapsed) instance a cfdata index.
173  * Note that there may still be aliases among these.
174  */
175 struct devi {
176 	/* created while parsing config file */
177 	const char *i_name;	/* e.g., "sd0" */
178 	int	i_unit;		/* unit from name, e.g., 0 */
179 	int	i_disable;	/* device is disabled */
180 	struct	devbase *i_base;/* e.g., pointer to "sd" base */
181 	struct	devi *i_next;	/* list of all instances */
182 	struct	devi *i_bsame;	/* list on same base */
183 	struct	devi *i_asame;	/* list on same base attachment */
184 	struct	devi *i_alias;	/* other aliases of this instance */
185 	const char *i_at;	/* where this is "at" (NULL if at root) */
186 	struct	attr *i_atattr;	/* attr that allowed attach */
187 	struct	devbase *i_atdev;/* if "at <devname><unit>", else NULL */
188 	struct	deva *i_atdeva;
189 	const char **i_locs;	/* locators (as given by i_atattr) */
190 	int	i_atunit;	/* unit from "at" */
191 	int	i_cfflags;	/* flags from config line */
192 	int	i_lineno;	/* line # in config, for later errors */
193 
194 	/* created during packing or ioconf.c generation */
195 /* 		i_loclen	   via i_atattr->a_loclen */
196 	short	i_collapsed;	/* set => this alias no longer needed */
197 	short	i_cfindex;	/* our index in cfdata */
198 	short	i_pvlen;	/* number of parents */
199 	short	i_pvoff;	/* offset in parents.vec */
200 	short	i_locoff;	/* offset in locators.vec */
201 	struct	devi **i_parents;/* the parents themselves */
202 	int	i_locnami;	/* my index into locnami[] */
203 	int	i_plocnami;	/* parent's locnami[] index */
204 };
205 /* special units */
206 #define	STAR	(-1)		/* unit number for, e.g., "sd*" */
207 #define	WILD	(-2)		/* unit number for, e.g., "sd?" */
208 
209 /*
210  * Files.  Each file is either standard (always included) or optional,
211  * depending on whether it has names on which to *be* optional.  The
212  * options field (fi_optx) is actually an expression tree, with nodes
213  * for OR, AND, and NOT, as well as atoms (words) representing some
214  * particular option.  The node type is stored in the nv_int field.
215  * Subexpressions appear in the `next' field; for the binary operators
216  * AND and OR, the left subexpression is first stored in the nv_ptr field.
217  *
218  * For any file marked as needs-count or needs-flag, fixfiles() will
219  * build fi_optf, a `flat list' of the options with nv_int fields that
220  * contain counts or `need' flags; this is used in mkheaders().
221  */
222 struct files {
223 	struct	files *fi_next;	/* linked list */
224 	const char *fi_srcfile;	/* the name of the "files" file that got us */
225 	u_short	fi_srcline;	/* and the line number */
226 	u_char	fi_flags;	/* as below */
227 	char	fi_lastc;	/* last char from path */
228 	const char *fi_path;	/* full file path */
229 	const char *fi_tail;	/* name, i.e., strrchr(fi_path, '/') + 1 */
230 	const char *fi_base;	/* tail minus ".c" (or whatever) */
231 	struct  nvlist *fi_optx;/* options expression */
232 	struct  nvlist *fi_optf;/* flattened version of above, if needed */
233 	const char *fi_mkrule;	/* special make rule, if any */
234 };
235 
236 /*
237  * Objects and libraries.  This allows precompiled object and library
238  * files (e.g. binary-only device drivers) to be linked in.
239  */
240 struct objects {
241 	struct  objects *oi_next;/* linked list */
242 	const char *oi_srcfile; /* the name of the "objects" file that got us */
243 	u_short oi_srcline;     /* and the line number */
244 	u_char  oi_flags;       /* as below */
245 	char    oi_lastc;       /* last char from path */
246 	const char *oi_path;    /* full object path */
247 	struct  nvlist *oi_optx;/* options expression */
248 	struct  nvlist *oi_optf;/* flattened version of above, if needed */
249 };
250 
251 #define	OI_SEL		0x01	/* selected */
252 #define	OI_NEEDSFLAG	0x02	/* needs-flag */
253 
254 #define	FX_ATOM		0	/* atom (in nv_name) */
255 #define	FX_NOT		1	/* NOT expr (subexpression in nv_next) */
256 #define	FX_AND		2	/* AND expr (lhs in nv_ptr, rhs in nv_next) */
257 #define	FX_OR		3	/* OR expr (lhs in nv_ptr, rhs in nv_next) */
258 
259 /* flags */
260 #define	FI_SEL		0x01	/* selected */
261 #define	FI_NEEDSCOUNT	0x02	/* needs-count */
262 #define	FI_NEEDSFLAG	0x04	/* needs-flag */
263 #define	FI_HIDDEN	0x08	/* obscured by other(s), base names overlap */
264 
265 /*
266  * Hash tables look up name=value pairs.  The pointer value of the name
267  * is assumed to be constant forever; this can be arranged by interning
268  * the name.  (This is fairly convenient since our lexer does this for
269  * all identifier-like strings---it has to save them anyway, lest yacc's
270  * look-ahead wipe out the current one.)
271  */
272 struct hashtab;
273 
274 const char *conffile;		/* source file, e.g., "GENERIC.sparc" */
275 const char *machine;		/* machine type, e.g., "sparc" or "sun3" */
276 const char *machinearch;	/* machine arch, e.g., "sparc" or "m68k" */
277 const char *srcdir;		/* path to source directory (rel. to build) */
278 const char *builddir;		/* path to build directory */
279 const char *defbuilddir;	/* default build directory */
280 int	errors;			/* counts calls to error() */
281 int	minmaxusers;		/* minimum "maxusers" parameter */
282 int	defmaxusers;		/* default "maxusers" parameter */
283 int	maxmaxusers;		/* default "maxusers" parameter */
284 int	maxusers;		/* configuration's "maxusers" parameter */
285 int	maxpartitions;		/* configuration's "maxpartitions" parameter */
286 struct	nvlist *options;	/* options */
287 struct	nvlist *defoptions;	/* "defopt"'d options */
288 struct	nvlist *mkoptions;	/* makeoptions */
289 struct	hashtab *devbasetab;	/* devbase lookup */
290 struct	hashtab *devatab;	/* devbase attachment lookup */
291 struct	hashtab *selecttab;	/* selects things that are "optional foo" */
292 struct	hashtab *needcnttab;	/* retains names marked "needs-count" */
293 struct	hashtab *opttab;	/* table of configured options */
294 struct	hashtab *defopttab;	/* options that have been "defopt"'d */
295 struct	devbase *allbases;	/* list of all devbase structures */
296 struct	deva *alldevas;		/* list of all devbase attachment structures */
297 struct	config *allcf;		/* list of configured kernels */
298 struct	devi *alldevi;		/* list of all instances */
299 struct	devi *allpseudo;	/* list of all pseudo-devices */
300 int	ndevi;			/* number of devi's (before packing) */
301 int	npseudo;		/* number of pseudo's */
302 
303 struct	files *allfiles;	/* list of all kernel source files */
304 struct objects *allobjects;	/* list of all kernel object and library files */
305 
306 struct	devi **packed;		/* arrayified table for packed devi's */
307 int	npacked;		/* size of packed table, <= ndevi */
308 
309 struct {			/* pv[] table for config */
310 	short	*vec;
311 	int	used;
312 } parents;
313 struct {			/* loc[] table for config */
314 	const char **vec;
315 	int	used;
316 } locators;
317 
318 /* files.c */
319 void	initfiles(void);
320 void	checkfiles(void);
321 int	fixfiles(void);		/* finalize */
322 int	fixobjects(void);
323 void	addfile(const char *, struct nvlist *, int, const char *);
324 void	addobject(const char *, struct nvlist *, int);
325 
326 /* hash.c */
327 struct	hashtab *ht_new(void);
328 int	ht_insrep(struct hashtab *, const char *, void *, int);
329 int     ht_remove(struct hashtab *, const char *);
330 #define	ht_insert(ht, nam, val) ht_insrep(ht, nam, val, 0)
331 #define	ht_replace(ht, nam, val) ht_insrep(ht, nam, val, 1)
332 void	*ht_lookup(struct hashtab *, const char *);
333 void	initintern(void);
334 const char *intern(const char *);
335 
336 /* main.c */
337 void	addoption(const char *name, const char *value);
338 void	removeoption(const char *name);
339 void	addmkoption(const char *name, const char *value);
340 void	defoption(const char *name);
341 int	devbase_has_instances(struct devbase *, int);
342 int	deva_has_instances(struct deva *, int);
343 void	setupdirs(void);
344 
345 /* mkheaders.c */
346 int	mkheaders(void);
347 
348 /* mkioconf.c */
349 int	mkioconf(void);
350 
351 /* mkmakefile.c */
352 int	mkmakefile(void);
353 
354 /* mkswap.c */
355 int	mkswap(void);
356 
357 /* pack.c */
358 void	pack(void);
359 
360 /* scan.l */
361 int	currentline(void);
362 int	firstfile(const char *);
363 int	include(const char *, int);
364 
365 /* sem.c, other than for yacc actions */
366 void	initsem(void);
367 
368 /* util.c */
369 void	*emalloc(size_t);
370 void	*erealloc(void *, size_t);
371 char	*sourcepath(const char *);
372 void	error(const char *, ...);			/* immediate errs */
373 void	xerror(const char *, int, const char *, ...);	/* delayed errs */
374 __dead void panic(const char *, ...);
375 struct nvlist *newnv(const char *, const char *, void *, int, struct nvlist *);
376 void	nvfree(struct nvlist *);
377 void	nvfreel(struct nvlist *);
378 
379 int	ukc(char *, char *, int, int);
380