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