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