* Copyright (c) 1992, 1993
* The Regents of the University of California. All rights reserved.
* This software was developed by the Computer Systems Engineering group
* at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and
* contributed to Berkeley.
* All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by the University of
* California, Lawrence Berkeley Laboratories.
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by the University of
* California, Berkeley and its contributors.
* 4. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* @(#)mkioconf.c 8.1 (Berkeley) 6/6/93
static int cforder
__P((const void *, const void *));
static int emitcfdata
__P((FILE *));
static int emitexterns
__P((FILE *));
static int emithdr
__P((FILE *));
static int emitloc
__P((FILE *));
static int emitpseudo
__P((FILE *));
static int emitpv
__P((FILE *));
static int emitroots
__P((FILE *));
static int emitvec
__P((FILE *));
static char *vecname
__P((char *, const char *, int));
static const char *s_i386
;
#define SEP(pos, max) (((u_int)(pos) % (max)) == 0 ? "\n\t" : " ")
* NEWLINE can only be used in the emitXXX functions.
* In most cases it can be subsumed into an fprintf.
#define NEWLINE if (putc('\n', fp) < 0) return (1)
fname
= path("ioconf.c");
qsort(packed
, npacked
, sizeof *packed
, cforder
);
if ((fp
= fopen(fname
, "w")) == NULL
) {
(void)fprintf(stderr
, "config: cannot write %s: %s\n",
if (v
!= 0 || emitvec(fp
) || emitexterns(fp
) || emitloc(fp
) ||
emitpv(fp
) || emitcfdata(fp
) || emitroots(fp
) || emitpseudo(fp
)) {
"config: error writing %s: %s\n",
/* (void)unlink(fname); */
n1
= (*(struct devi
**)a
)->i_cfindex
;
n2
= (*(struct devi
**)b
)->i_cfindex
;
char ifn
[200], buf
[BUFSIZ
];
* MACHINE GENERATED: DO NOT EDIT\n\
* ioconf.c, from \"%s\"\n\
(void)sprintf(ifn
, "ioconf.incl.%s", machine
);
if ((ifp
= fopen(ifn
, "r")) != NULL
) {
while ((n
= fread(buf
, 1, sizeof(buf
), ifp
)) > 0)
if (fwrite(buf
, 1, n
, ofp
) != n
)
(void)fprintf(stderr
, "config: error reading %s: %s\n",
#include <sys/param.h>\n\
#include <sys/device.h>\n", ofp
) < 0)
register struct devbase
*d
;
for (d
= allbases
; d
!= NULL
; d
= d
->d_next
) {
if (fprintf(fp
, "extern struct cfdriver %scd;\n",
if (fprintf(fp
, "\n/* locators */\n\
static int loc[%d] = {", locators
.used
) < 0)
for (i
= 0; i
< locators
.used
; i
++)
if (fprintf(fp
, "%s%s,", SEP(i
, 8), locators
.vec
[i
]) < 0)
return (fprintf(fp
, "\n};\n") < 0);
* Emit global parents-vector.
if (fprintf(fp
, "\n/* parent vectors */\n\
static short pv[%d] = {", parents
.used
) < 0)
for (i
= 0; i
< parents
.used
; i
++)
if (fprintf(fp
, "%s%d,", SEP(i
, 16), parents
.vec
[i
]) < 0)
return (fprintf(fp
, "\n};\n") < 0);
register struct devi
**p
, *i
, **par
;
register const char *vs
, *state
, *basename
;
register struct nvlist
*nv
;
#define NORM FSTATE_NOTFOUND\n\
#define STAR FSTATE_STAR\n\
struct cfdata cfdata[] = {\n\
\t/* driver unit state loc flags parents ivstubs */\n") < 0)
for (p
= packed
; (i
= *p
) != NULL
; p
++) {
if (fprintf(fp
, "/*%3d: %s at ", i
->i_cfindex
, i
->i_name
) < 0)
for (v
= 0; v
< i
->i_pvlen
; v
++)
if (fprintf(fp
, "%s%s", v
== 0 ? "" : "|",
i
->i_parents
[v
]->i_name
) < 0)
if (v
== 0 && fputs("root", fp
) < 0)
for (nv
= a
->a_locs
, v
= 0; nv
!= NULL
; nv
= nv
->nv_next
, v
++)
if (fprintf(fp
, " %s %s",
nv
->nv_name
, i
->i_locs
[v
]) < 0)
if (fputs(" */\n", fp
) < 0)
/* then the actual defining line */
basename
= i
->i_base
->d_name
;
unit
= i
->i_base
->d_umax
;
(void)sprintf(locbuf
, "loc+%3d", i
->i_locoff
);
\t{&%scd,%s%2d, %s, %7s, %#6x, pv+%2d, %s%d},\n",
basename
, strlen(basename
) < 3 ? "\t\t" : "\t", unit
,
state
, loc
, i
->i_cfflags
, i
->i_pvoff
, vs
, v
) < 0)
return (fputs("\t{0}\n};\n", fp
) < 0);
* Emit the table of potential roots.
register struct devi
**p
, *i
;
if (fputs("\nshort cfroots[] = {\n", fp
) < 0)
for (p
= packed
; (i
= *p
) != NULL
; p
++) {
(i
->i_unit
!= STAR
|| i
->i_base
->d_umax
!= 0))
"config: warning: `%s at root' is not unit 0\n",
if (fprintf(fp
, "\t%2d /* %s */,\n",
i
->i_cfindex
, i
->i_name
) < 0)
return (fputs("\t-1\n};\n", fp
) < 0);
* Emit pseudo-device initialization.
register struct devbase
*d
;
if (fputs("\n/* pseudo-devices */\n", fp
) < 0)
for (i
= allpseudo
; i
!= NULL
; i
= i
->i_next
)
if (fprintf(fp
, "extern void %sattach __P((int));\n",
if (fputs("\nstruct pdevinit pdevinit[] = {\n", fp
) < 0)
for (i
= allpseudo
; i
!= NULL
; i
= i
->i_next
) {
if (fprintf(fp
, "\t{ %sattach, %d },\n",
d
->d_name
, d
->d_umax
) < 0)
return (fputs("\t{ 0, 0 }\n};\n", fp
) < 0);
* Emit interrupt vector declarations, and calculate offsets.
register struct nvlist
*head
, *nv
;
register struct devi
**p
, *i
;
register int j
, nvec
, unit
;
for (p
= packed
; (i
= *p
) != NULL
; p
++) {
if ((head
= i
->i_base
->d_vectors
) == NULL
)
if ((unit
= i
->i_unit
) == STAR
)
panic("emitvec unit==STAR");
for (j
= 0, nv
= head
; nv
!= NULL
; j
++, nv
= nv
->nv_next
)
"/* IVEC %s %d */ extern void %s();\n",
vecname(buf
, nv
->nv_name
, unit
)) < 0)
if (fprintf(fp
, "\nstatic void (*vec[%d]) __P((void)) = {", nvec
) < 0)
for (p
= packed
; (i
= *p
) != NULL
; p
++) {
if ((head
= i
->i_base
->d_vectors
) == NULL
)
for (nv
= head
; nv
!= NULL
; nv
= nv
->nv_next
)
vecname(buf
, nv
->nv_name
, unit
)) < 0)
if (fprintf(fp
, "%s0,", SEP(nvec
++, 4)) < 0)
return (fputs("\n};\n", fp
) < 0);
/* @#%* 386 uses a different name format */
(void)sprintf(buf
, "V%s%d", name
, unit
);
(void)sprintf(buf
, "X%s%d", name
, unit
);