fully make libraries
[unix-history] / usr / src / usr.sbin / config / mkioconf.c
CommitLineData
36e00264 1/* mkioconf.c 2.3 82/10/24 */
5e794bde 2
b88ba334
BJ
3#include <stdio.h>
4#include "y.tab.h"
5#include "config.h"
6
7/*
5e794bde 8 * build the ioconf.c file
b88ba334 9 */
5e794bde 10char *qu();
b88ba334 11
5e794bde 12vax_ioconf()
b88ba334 13{
5e794bde
BJ
14 register struct device *dp, *mp, *np;
15 register int uba_n, slave;
16 char *intv();
17 FILE *fp;
b88ba334 18
5e794bde
BJ
19 fp = fopen(path("ioconf.c"), "w");
20 if (fp == NULL) {
21 perror(path("ioconf.c"));
22 exit(1);
b88ba334 23 }
5e794bde
BJ
24 fprintf(fp, "#include \"../h/param.h\"\n");
25 fprintf(fp, "#include \"../h/pte.h\"\n");
26 fprintf(fp, "#include \"../h/buf.h\"\n");
27 fprintf(fp, "#include \"../h/map.h\"\n");
28 fprintf(fp, "#include \"../h/vm.h\"\n");
29 fprintf(fp, "\n");
30 fprintf(fp, "#include \"../vaxmba/mbavar.h\"\n");
31 fprintf(fp, "#include \"../vaxuba/ubavar.h\"\n\n");
32 fprintf(fp, "\n");
33 fprintf(fp, "#define C (caddr_t)\n\n");
34 /*
35 * First print the mba initialization structures
36 */
37 if (seen_mba) {
38 for (dp = dtab; dp != NULL; dp = dp->d_next) {
39 mp = dp->d_conn;
40 if (mp == NULL || mp == TO_NEXUS ||
41 !eq(mp->d_name, "mba"))
42 continue;
43 fprintf(fp, "extern struct mba_driver %sdriver;\n",
44 dp->d_name);
45 }
46 fprintf(fp, "\nstruct mba_device mbdinit[] = {\n");
47 fprintf(fp, "\t/* Device, Unit, Mba, Drive, Dk */\n");
48 for (dp = dtab; dp != NULL; dp = dp->d_next) {
49 mp = dp->d_conn;
50 if (dp->d_unit == QUES || mp == NULL ||
51 mp == TO_NEXUS || !eq(mp->d_name, "mba"))
52 continue;
53 if (dp->d_addr) {
54 printf("can't specify csr address on mba for %s%d\n",
55 dp->d_name, dp->d_unit);
56 continue;
57 }
58 if (dp->d_vec != NULL) {
59 printf("can't specify vector for %s%d on mba\n",
60 dp->d_name, dp->d_unit);
61 continue;
62 }
63 if (dp->d_drive == UNKNOWN) {
64 printf("drive not specified for %s%d\n",
65 dp->d_name, dp->d_unit);
66 continue;
67 }
68 if (dp->d_slave != UNKNOWN) {
69 printf("can't specify slave number for %s%d\n",
70 dp->d_name, dp->d_unit);
71 continue;
72 }
73 fprintf(fp,
74 "\t{ &%sdriver, %d, %s, %s, %d },\n",
75 dp->d_name, dp->d_unit, qu(mp->d_unit),
76 qu(dp->d_drive), dp->d_dk);
77 }
78 fprintf(fp, "\t0\n};\n\n");
79 /*
80 * Print the mbsinit structure
81 * Driver Controller Unit Slave
82 */
83 fprintf(fp, "struct mba_slave mbsinit [] = {\n");
84 fprintf(fp, "\t/* Driver, Ctlr, Unit, Slave */\n");
85 for (dp = dtab; dp != NULL; dp = dp->d_next) {
86 /*
87 * All slaves are connected to something which
88 * is connected to the massbus.
89 */
90 if ((mp = dp->d_conn) == NULL || mp == TO_NEXUS)
91 continue;
92 np = mp->d_conn;
93 if (np == NULL || np == TO_NEXUS ||
94 !eq(np->d_name, "mba"))
95 continue;
96 fprintf(fp,
97 "\t{ &%sdriver, %s, %2d, %s },\n",
98 mp->d_name, qu(mp->d_unit), dp->d_unit,
99 qu(dp->d_slave));
100 }
101 fprintf(fp, "\t0\n};\n\n");
b88ba334 102 }
b88ba334 103 /*
5e794bde 104 * Now generate interrupt vectors for the unibus
b88ba334 105 */
5e794bde
BJ
106 for (dp = dtab; dp != NULL; dp = dp->d_next) {
107 if (dp->d_vec != NULL) {
108 struct idlst *ip;
109 mp = dp->d_conn;
110 if (mp == NULL || mp == TO_NEXUS ||
111 !eq(mp->d_name, "uba"))
112 continue;
113 fprintf(fp,
114 "extern struct uba_driver %sdriver;\n",
115 dp->d_name);
116 fprintf(fp, "extern ");
117 ip = dp->d_vec;
118 for (;;) {
119 fprintf(fp, "X%s%d()", ip->id, dp->d_unit);
120 ip = ip->id_next;
121 if (ip == 0)
122 break;
123 fprintf(fp, ", ");
124 }
125 fprintf(fp, ";\n");
126 fprintf(fp, "int\t (*%sint%d[])() = { ", dp->d_name,
127 dp->d_unit, dp->d_unit);
128 ip = dp->d_vec;
129 for (;;) {
130 fprintf(fp, "X%s%d", ip->id, dp->d_unit);
131 ip = ip->id_next;
132 if (ip == 0)
133 break;
134 fprintf(fp, ", ");
135 }
136 fprintf(fp, ", 0 } ;\n");
137 }
b88ba334 138 }
5e794bde
BJ
139 fprintf(fp, "\nstruct uba_ctlr ubminit[] = {\n");
140 fprintf(fp, "/*\t driver,\tctlr,\tubanum,\talive,\tintr,\taddr */\n");
141 for (dp = dtab; dp != NULL; dp = dp->d_next) {
142 mp = dp->d_conn;
143 if (dp->d_type != CONTROLLER || mp == TO_NEXUS || mp == NULL ||
144 !eq(mp->d_name, "uba"))
145 continue;
146 if (dp->d_vec == 0) {
147 printf("must specify vector for %s%d\n",
148 dp->d_name, dp->d_unit);
149 continue;
150 }
151 if (dp->d_addr == 0) {
152 printf("must specify csr address for %s%d\n",
153 dp->d_name, dp->d_unit);
154 continue;
155 }
156 if (dp->d_drive != UNKNOWN || dp->d_slave != UNKNOWN) {
157 printf("drives need their own entries; dont ");
158 printf("specify drive or slave for %s%d\n",
159 dp->d_name, dp->d_unit);
160 continue;
161 }
162 if (dp->d_flags) {
163 printf("controllers (e.g. %s%d) ",
164 dp->d_name, dp->d_unit);
165 printf("don't have flags, only devices do\n");
166 continue;
167 }
168 fprintf(fp,
169 "\t{ &%sdriver,\t%d,\t%s,\t0,\t%sint%d, C 0%o },\n",
170 dp->d_name, dp->d_unit, qu(mp->d_unit),
171 dp->d_name, dp->d_unit, dp->d_addr);
b88ba334 172 }
5e794bde 173 fprintf(fp, "\t0\n};\n");
36e00264 174/* unibus devices */
5e794bde 175 fprintf(fp, "\nstruct uba_device ubdinit[] = {\n");
36e00264
BJ
176 fprintf(fp,
177"\t/* driver, unit, ctlr, ubanum, slave, intr, addr, dk, flags*/\n");
5e794bde
BJ
178 for (dp = dtab; dp != NULL; dp = dp->d_next) {
179 mp = dp->d_conn;
180 if (dp->d_unit == QUES || dp->d_type != DEVICE || mp == NULL ||
181 mp == TO_NEXUS || mp->d_type == MASTER ||
182 eq(mp->d_name, "mba"))
183 continue;
184 np = mp->d_conn;
185 if (np != NULL && np != TO_NEXUS && eq(np->d_name, "mba"))
186 continue;
187 np = NULL;
188 if (eq(mp->d_name, "uba")) {
189 if (dp->d_vec == 0) {
190 printf("must specify vector for device %s%d\n",
191 dp->d_name, dp->d_unit);
192 continue;
193 }
194 if (dp->d_addr == 0) {
195 printf("must specify csr for device %s%d\n",
196 dp->d_name, dp->d_unit);
197 continue;
198 }
199 if (dp->d_drive != UNKNOWN || dp->d_slave != UNKNOWN) {
200 printf("drives/slaves can be specified ");
201 printf("only for controllers, ");
202 printf("not for device %s%d\n",
203 dp->d_name, dp->d_unit);
204 continue;
205 }
206 uba_n = mp->d_unit;
207 slave = QUES;
208 } else {
209 if ((np = mp->d_conn) == NULL) {
210 printf("%s%d isn't connected to anything ",
211 mp->d_name, mp->d_unit);
212 printf(", so %s%d is unattached\n",
213 dp->d_name, dp->d_unit);
214 continue;
215 }
216 uba_n = np->d_unit;
217 if (dp->d_drive == UNKNOWN) {
218 printf("must specify ``drive number'' ");
219 printf("for %s%d\n", dp->d_name, dp->d_unit);
220 continue;
221 }
222 /* NOTE THAT ON THE UNIBUS ``drive'' IS STORED IN */
223 /* ``SLAVE'' AND WE DON'T WANT A SLAVE SPECIFIED */
224 if (dp->d_slave != UNKNOWN) {
225 printf("slave numbers should be given only ");
226 printf("for massbus tapes, not for %s%d\n",
227 dp->d_name, dp->d_unit);
228 continue;
229 }
230 if (dp->d_vec != 0) {
231 printf("interrupt vectors should not be ");
232 printf("given for drive %s%d\n",
233 dp->d_name, dp->d_unit);
234 continue;
235 }
236 if (dp->d_addr != 0) {
237 printf("csr addresses should be given only ");
238 printf("on controllers, not on %s%d\n",
239 dp->d_name, dp->d_unit);
240 continue;
241 }
242 slave = dp->d_drive;
243 }
244 fprintf(fp,
245"\t{ &%sdriver, %2d, %s, %s, %2d, %s, C 0%-6o, %d, 0x%x },\n",
246 eq(mp->d_name, "uba") ? dp->d_name : mp->d_name, dp->d_unit,
247 eq(mp->d_name, "uba") ? " -1" : qu(mp->d_unit), qu(uba_n),
248 slave, intv(dp), dp->d_addr, dp->d_dk, dp->d_flags);
b88ba334 249 }
5e794bde
BJ
250 fprintf(fp, "\t0\n};\n");
251 fclose(fp);
252}
253
254sun_ioconf()
255{
256 register struct device *dp, *mp, *np;
257 register int uba_n, slave;
258 char *intv();
259 FILE *fp;
260
261 fp = fopen(path("ioconf.c"), "w");
262 if (fp == NULL) {
263 perror(path("ioconf.c"));
264 exit(1);
b88ba334 265 }
5e794bde
BJ
266 fprintf(fp, "#include \"../h/param.h\"\n");
267 fprintf(fp, "#include \"../h/buf.h\"\n");
268 fprintf(fp, "#include \"../h/map.h\"\n");
269 fprintf(fp, "#include \"../h/vm.h\"\n");
270 fprintf(fp, "\n");
271 fprintf(fp, "#include \"../sunmb/mbvar.h\"\n");
272 fprintf(fp, "\n");
273 fprintf(fp, "#define C (caddr_t)\n\n");
274 fprintf(fp, "\n");
275 /*
276 * Now generate interrupt vectors for the Multibus
277 */
278 for (dp = dtab; dp != NULL; dp = dp->d_next) {
279 if (dp->d_pri != NULL) {
280 mp = dp->d_conn;
281 if (mp == NULL || mp == TO_NEXUS ||
282 !eq(mp->d_name, "mb"))
283 continue;
284 fprintf(fp, "extern struct mb_driver %sdriver;\n",
285 dp->d_name);
286 }
b88ba334 287 }
5e794bde
BJ
288 /*
289 * Now spew forth the mb_cinfo structure
290 */
291 fprintf(fp, "\nstruct mb_ctlr mbcinit[] = {\n");
292 fprintf(fp, "/*\t driver,\tctlr,\talive,\taddr,\tintpri */\n");
293 for (dp = dtab; dp != NULL; dp = dp->d_next) {
294 mp = dp->d_conn;
295 if (dp->d_type != CONTROLLER || mp == TO_NEXUS || mp == NULL ||
296 !eq(mp->d_name, "mb"))
297 continue;
298 if (dp->d_pri == 0) {
299 printf("must specify priority for %s%d\n",
300 dp->d_name, dp->d_unit);
301 continue;
302 }
303 if (dp->d_addr == 0) {
304 printf("must specify csr address for %s%d\n",
305 dp->d_name, dp->d_unit);
306 continue;
307 }
308 if (dp->d_drive != UNKNOWN || dp->d_slave != UNKNOWN) {
309 printf("drives need their own entries; ");
310 printf("dont specify drive or slave for %s%d\n",
311 dp->d_name, dp->d_unit);
312 continue;
313 }
314 if (dp->d_flags) {
315 printf("controllers (e.g. %s%d) don't have flags, ");
316 printf("only devices do\n",
317 dp->d_name, dp->d_unit);
318 continue;
319 }
320 fprintf(fp, "\t{ &%sdriver,\t%d,\t0,\tC 0x%x,\t%d },\n",
321 dp->d_name, dp->d_unit, dp->d_addr, dp->d_pri);
b88ba334 322 }
5e794bde
BJ
323 fprintf(fp, "\t0\n};\n");
324 /*
325 * Now we go for the mb_device stuff
326 */
327 fprintf(fp, "\nstruct mb_device mbdinit[] = {\n");
328 fprintf(fp,
329"\t/* driver, unit, ctlr, slave, addr, pri, dk, flags*/\n");
330 for (dp = dtab; dp != NULL; dp = dp->d_next) {
331 mp = dp->d_conn;
332 if (dp->d_unit == QUES || dp->d_type != DEVICE || mp == NULL ||
333 mp == TO_NEXUS || mp->d_type == MASTER ||
334 eq(mp->d_name, "mba"))
335 continue;
336 np = NULL;
337 if (eq(mp->d_name, "mb")) {
338 if (dp->d_pri == 0) {
339 printf("must specify vector for device %s%d\n",
340 dp->d_name, dp->d_unit);
341 continue;
342 }
343 if (dp->d_addr == 0) {
344 printf("must specify csr for device %s%d\n",
345 dp->d_name, dp->d_unit);
346 continue;
347 }
348 if (dp->d_drive != UNKNOWN || dp->d_slave != UNKNOWN) {
349 printf("drives/slaves can be specified only ");
350 printf("for controllers, not for device %s%d\n",
351 dp->d_name, dp->d_unit);
352 continue;
353 }
354 slave = QUES;
355 } else {
356 if ((np = mp->d_conn) == NULL) {
357 printf("%s%d isn't connected to anything, ",
358 mp->d_name, mp->d_unit);
359 printf("so %s%d is unattached\n",
360 dp->d_name, dp->d_unit);
361 continue;
362 }
363 if (dp->d_drive == UNKNOWN) {
364 printf("must specify ``drive number'' for %s%d\n",
365 dp->d_name, dp->d_unit);
366 continue;
367 }
368 /* NOTE THAT ON THE UNIBUS ``drive'' IS STORED IN */
369 /* ``SLAVE'' AND WE DON'T WANT A SLAVE SPECIFIED */
370 if (dp->d_slave != UNKNOWN) {
371 printf("slave numbers should be given only ");
372 printf("for massbus tapes, not for %s%d\n",
373 dp->d_name, dp->d_unit);
374 continue;
375 }
376 if (dp->d_pri != 0) {
377 printf("interrupt priority should not be ");
378 printf("given for drive %s%d\n",
379 dp->d_name, dp->d_unit);
380 continue;
381 }
382 if (dp->d_addr != 0) {
383 printf("csr addresses should be given only");
384 printf("on controllers, not on %s%d\n",
385 dp->d_name, dp->d_unit);
386 continue;
387 }
388 slave = dp->d_drive;
389 }
390 fprintf(fp,
391"\t{ &%sdriver, %2d, %s, %2d, C 0x%x, %d, %d, 0x%x },\n",
392 eq(mp->d_name, "mb") ? dp->d_name : mp->d_name, dp->d_unit,
393 eq(mp->d_name, "mb") ? " -1" : qu(mp->d_unit),
394 slave, dp->d_addr, dp->d_pri, dp->d_dk, dp->d_flags);
b88ba334 395 }
5e794bde
BJ
396 fprintf(fp, "\t0\n};\n");
397 fclose(fp);
b88ba334
BJ
398}
399
b88ba334 400char *intv(dev)
5e794bde 401 register struct device *dev;
b88ba334
BJ
402{
403 static char buf[20];
404
5e794bde
BJ
405 if (dev->d_vec == 0)
406 return (" 0");
b88ba334 407 else
5e794bde 408 return (sprintf(buf, "%sint%d", dev->d_name, dev->d_unit));
b88ba334
BJ
409}
410
411char *
412qu(num)
413{
5e794bde 414
b88ba334 415 if (num == QUES)
5e794bde
BJ
416 return ("'?'");
417 else if (num == UNKNOWN)
418 return (" -1");
419 else
420 return (ns(sprintf(errbuf, "%3d", num)));
b88ba334 421}