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