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