install correct aliases file
[unix-history] / usr / src / usr.sbin / config / mkioconf.c
CommitLineData
cd68466f
DF
1/*
2 * Copyright (c) 1980 Regents of the University of California.
86f9c1e9
KB
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms are permitted
b8c620d6
KB
6 * provided that the above copyright notice and this paragraph are
7 * duplicated in all such forms and that any documentation,
8 * advertising materials, and other materials related to such
9 * distribution and use acknowledge that the software was developed
10 * by the University of California, Berkeley. The name of the
11 * University may not be used to endorse or promote products derived
12 * from this software without specific prior written permission.
13 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
14 * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
15 * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
cd68466f
DF
16 */
17
524aa063 18#ifndef lint
b8c620d6 19static char sccsid[] = "@(#)mkioconf.c 5.10 (Berkeley) %G%";
86f9c1e9 20#endif /* not lint */
5e794bde 21
b88ba334
BJ
22#include <stdio.h>
23#include "y.tab.h"
24#include "config.h"
25
26/*
5e794bde 27 * build the ioconf.c file
b88ba334 28 */
5e794bde 29char *qu();
b312f544 30char *intv();
b88ba334 31
b312f544 32#if MACHINE_VAX
5e794bde 33vax_ioconf()
b88ba334 34{
5e794bde
BJ
35 register struct device *dp, *mp, *np;
36 register int uba_n, slave;
5e794bde 37 FILE *fp;
b88ba334 38
5e794bde 39 fp = fopen(path("ioconf.c"), "w");
22d68ad0 40 if (fp == 0) {
5e794bde
BJ
41 perror(path("ioconf.c"));
42 exit(1);
b88ba334 43 }
107dc11a 44 fprintf(fp, "#include \"../machine/pte.h\"\n");
5e794bde 45 fprintf(fp, "#include \"../h/param.h\"\n");
5e794bde
BJ
46 fprintf(fp, "#include \"../h/buf.h\"\n");
47 fprintf(fp, "#include \"../h/map.h\"\n");
48 fprintf(fp, "#include \"../h/vm.h\"\n");
49 fprintf(fp, "\n");
50 fprintf(fp, "#include \"../vaxmba/mbavar.h\"\n");
51 fprintf(fp, "#include \"../vaxuba/ubavar.h\"\n\n");
52 fprintf(fp, "\n");
53 fprintf(fp, "#define C (caddr_t)\n\n");
54 /*
55 * First print the mba initialization structures
56 */
57 if (seen_mba) {
22d68ad0 58 for (dp = dtab; dp != 0; dp = dp->d_next) {
5e794bde 59 mp = dp->d_conn;
22d68ad0 60 if (mp == 0 || mp == TO_NEXUS ||
5e794bde
BJ
61 !eq(mp->d_name, "mba"))
62 continue;
63 fprintf(fp, "extern struct mba_driver %sdriver;\n",
64 dp->d_name);
65 }
66 fprintf(fp, "\nstruct mba_device mbdinit[] = {\n");
67 fprintf(fp, "\t/* Device, Unit, Mba, Drive, Dk */\n");
22d68ad0 68 for (dp = dtab; dp != 0; dp = dp->d_next) {
5e794bde 69 mp = dp->d_conn;
22d68ad0 70 if (dp->d_unit == QUES || mp == 0 ||
5e794bde
BJ
71 mp == TO_NEXUS || !eq(mp->d_name, "mba"))
72 continue;
73 if (dp->d_addr) {
74 printf("can't specify csr address on mba for %s%d\n",
75 dp->d_name, dp->d_unit);
76 continue;
77 }
22d68ad0 78 if (dp->d_vec != 0) {
5e794bde
BJ
79 printf("can't specify vector for %s%d on mba\n",
80 dp->d_name, dp->d_unit);
81 continue;
82 }
83 if (dp->d_drive == UNKNOWN) {
84 printf("drive not specified for %s%d\n",
85 dp->d_name, dp->d_unit);
86 continue;
87 }
88 if (dp->d_slave != UNKNOWN) {
89 printf("can't specify slave number for %s%d\n",
90 dp->d_name, dp->d_unit);
91 continue;
92 }
0c51914c
SL
93 fprintf(fp, "\t{ &%sdriver, %d, %s,",
94 dp->d_name, dp->d_unit, qu(mp->d_unit));
95 fprintf(fp, " %s, %d },\n",
5e794bde
BJ
96 qu(dp->d_drive), dp->d_dk);
97 }
98 fprintf(fp, "\t0\n};\n\n");
99 /*
100 * Print the mbsinit structure
101 * Driver Controller Unit Slave
102 */
103 fprintf(fp, "struct mba_slave mbsinit [] = {\n");
104 fprintf(fp, "\t/* Driver, Ctlr, Unit, Slave */\n");
22d68ad0 105 for (dp = dtab; dp != 0; dp = dp->d_next) {
5e794bde
BJ
106 /*
107 * All slaves are connected to something which
108 * is connected to the massbus.
109 */
22d68ad0 110 if ((mp = dp->d_conn) == 0 || mp == TO_NEXUS)
5e794bde
BJ
111 continue;
112 np = mp->d_conn;
22d68ad0 113 if (np == 0 || np == TO_NEXUS ||
5e794bde
BJ
114 !eq(np->d_name, "mba"))
115 continue;
0ad2198c
SL
116 fprintf(fp, "\t{ &%sdriver, %s",
117 mp->d_name, qu(mp->d_unit));
118 fprintf(fp, ", %2d, %s },\n",
119 dp->d_unit, qu(dp->d_slave));
5e794bde
BJ
120 }
121 fprintf(fp, "\t0\n};\n\n");
b88ba334 122 }
b88ba334 123 /*
5e794bde 124 * Now generate interrupt vectors for the unibus
b88ba334 125 */
22d68ad0
BJ
126 for (dp = dtab; dp != 0; dp = dp->d_next) {
127 if (dp->d_vec != 0) {
5e794bde
BJ
128 struct idlst *ip;
129 mp = dp->d_conn;
22d68ad0 130 if (mp == 0 || mp == TO_NEXUS ||
67259f7b 131 (!eq(mp->d_name, "uba") && !eq(mp->d_name, "bi")))
5e794bde
BJ
132 continue;
133 fprintf(fp,
134 "extern struct uba_driver %sdriver;\n",
135 dp->d_name);
136 fprintf(fp, "extern ");
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, ";\n");
146 fprintf(fp, "int\t (*%sint%d[])() = { ", dp->d_name,
a0897453 147 dp->d_unit);
5e794bde
BJ
148 ip = dp->d_vec;
149 for (;;) {
150 fprintf(fp, "X%s%d", ip->id, dp->d_unit);
151 ip = ip->id_next;
152 if (ip == 0)
153 break;
154 fprintf(fp, ", ");
155 }
156 fprintf(fp, ", 0 } ;\n");
157 }
b88ba334 158 }
5e794bde
BJ
159 fprintf(fp, "\nstruct uba_ctlr ubminit[] = {\n");
160 fprintf(fp, "/*\t driver,\tctlr,\tubanum,\talive,\tintr,\taddr */\n");
22d68ad0 161 for (dp = dtab; dp != 0; dp = dp->d_next) {
5e794bde 162 mp = dp->d_conn;
22d68ad0 163 if (dp->d_type != CONTROLLER || mp == TO_NEXUS || mp == 0 ||
5e794bde
BJ
164 !eq(mp->d_name, "uba"))
165 continue;
166 if (dp->d_vec == 0) {
167 printf("must specify vector for %s%d\n",
168 dp->d_name, dp->d_unit);
169 continue;
170 }
171 if (dp->d_addr == 0) {
172 printf("must specify csr address for %s%d\n",
173 dp->d_name, dp->d_unit);
174 continue;
175 }
176 if (dp->d_drive != UNKNOWN || dp->d_slave != UNKNOWN) {
177 printf("drives need their own entries; dont ");
178 printf("specify drive or slave for %s%d\n",
179 dp->d_name, dp->d_unit);
180 continue;
181 }
182 if (dp->d_flags) {
183 printf("controllers (e.g. %s%d) ",
184 dp->d_name, dp->d_unit);
185 printf("don't have flags, only devices do\n");
186 continue;
187 }
188 fprintf(fp,
189 "\t{ &%sdriver,\t%d,\t%s,\t0,\t%sint%d, C 0%o },\n",
190 dp->d_name, dp->d_unit, qu(mp->d_unit),
191 dp->d_name, dp->d_unit, dp->d_addr);
b88ba334 192 }
5e794bde 193 fprintf(fp, "\t0\n};\n");
36e00264 194/* unibus devices */
5e794bde 195 fprintf(fp, "\nstruct uba_device ubdinit[] = {\n");
36e00264
BJ
196 fprintf(fp,
197"\t/* driver, unit, ctlr, ubanum, slave, intr, addr, dk, flags*/\n");
22d68ad0 198 for (dp = dtab; dp != 0; dp = dp->d_next) {
5e794bde 199 mp = dp->d_conn;
22d68ad0 200 if (dp->d_unit == QUES || dp->d_type != DEVICE || mp == 0 ||
5e794bde
BJ
201 mp == TO_NEXUS || mp->d_type == MASTER ||
202 eq(mp->d_name, "mba"))
203 continue;
204 np = mp->d_conn;
22d68ad0 205 if (np != 0 && np != TO_NEXUS && eq(np->d_name, "mba"))
5e794bde 206 continue;
22d68ad0 207 np = 0;
5e794bde
BJ
208 if (eq(mp->d_name, "uba")) {
209 if (dp->d_vec == 0) {
210 printf("must specify vector for device %s%d\n",
211 dp->d_name, dp->d_unit);
212 continue;
213 }
214 if (dp->d_addr == 0) {
215 printf("must specify csr for device %s%d\n",
216 dp->d_name, dp->d_unit);
217 continue;
218 }
219 if (dp->d_drive != UNKNOWN || dp->d_slave != UNKNOWN) {
220 printf("drives/slaves can be specified ");
221 printf("only for controllers, ");
222 printf("not for device %s%d\n",
223 dp->d_name, dp->d_unit);
224 continue;
225 }
226 uba_n = mp->d_unit;
227 slave = QUES;
228 } else {
22d68ad0 229 if ((np = mp->d_conn) == 0) {
5e794bde
BJ
230 printf("%s%d isn't connected to anything ",
231 mp->d_name, mp->d_unit);
232 printf(", so %s%d is unattached\n",
233 dp->d_name, dp->d_unit);
234 continue;
235 }
236 uba_n = np->d_unit;
237 if (dp->d_drive == UNKNOWN) {
238 printf("must specify ``drive number'' ");
239 printf("for %s%d\n", dp->d_name, dp->d_unit);
240 continue;
241 }
242 /* NOTE THAT ON THE UNIBUS ``drive'' IS STORED IN */
243 /* ``SLAVE'' AND WE DON'T WANT A SLAVE SPECIFIED */
244 if (dp->d_slave != UNKNOWN) {
245 printf("slave numbers should be given only ");
246 printf("for massbus tapes, not for %s%d\n",
247 dp->d_name, dp->d_unit);
248 continue;
249 }
250 if (dp->d_vec != 0) {
251 printf("interrupt vectors should not be ");
252 printf("given for drive %s%d\n",
253 dp->d_name, dp->d_unit);
254 continue;
255 }
256 if (dp->d_addr != 0) {
257 printf("csr addresses should be given only ");
258 printf("on controllers, not on %s%d\n",
259 dp->d_name, dp->d_unit);
260 continue;
261 }
262 slave = dp->d_drive;
263 }
0c51914c 264 fprintf(fp, "\t{ &%sdriver, %2d, %s,",
5e794bde 265 eq(mp->d_name, "uba") ? dp->d_name : mp->d_name, dp->d_unit,
0c51914c
SL
266 eq(mp->d_name, "uba") ? " -1" : qu(mp->d_unit));
267 fprintf(fp, " %s, %2d, %s, C 0%-6o, %d, 0x%x },\n",
268 qu(uba_n), slave, intv(dp), dp->d_addr, dp->d_dk,
269 dp->d_flags);
b88ba334 270 }
5e794bde 271 fprintf(fp, "\t0\n};\n");
22d68ad0 272 (void) fclose(fp);
5e794bde 273}
b312f544 274#endif
5e794bde 275
a0105456
SL
276#if MACHINE_TAHOE
277tahoe_ioconf()
5e794bde 278{
a0105456
SL
279 register struct device *dp, *mp, *np;
280 register int vba_n, slave;
5e794bde
BJ
281 FILE *fp;
282
283 fp = fopen(path("ioconf.c"), "w");
22d68ad0 284 if (fp == 0) {
5e794bde
BJ
285 perror(path("ioconf.c"));
286 exit(1);
b88ba334 287 }
5e794bde 288 fprintf(fp, "#include \"../h/param.h\"\n");
a0105456 289 fprintf(fp, "#include \"../machine/pte.h\"\n");
5e794bde
BJ
290 fprintf(fp, "#include \"../h/buf.h\"\n");
291 fprintf(fp, "#include \"../h/map.h\"\n");
5e794bde 292 fprintf(fp, "\n");
a0105456 293 fprintf(fp, "#include \"../tahoevba/vbavar.h\"\n");
5e794bde
BJ
294 fprintf(fp, "\n");
295 fprintf(fp, "#define C (caddr_t)\n\n");
5e794bde 296 /*
a0105456 297 * Now generate interrupt vectors for the versabus
5e794bde 298 */
22d68ad0 299 for (dp = dtab; dp != 0; dp = dp->d_next) {
dff1a390
SL
300 mp = dp->d_conn;
301 if (mp == 0 || mp == TO_NEXUS || !eq(mp->d_name, "vba"))
302 continue;
a0105456
SL
303 if (dp->d_vec != 0) {
304 struct idlst *ip;
a0105456
SL
305 fprintf(fp,
306 "extern struct vba_driver %sdriver;\n",
5e794bde 307 dp->d_name);
a0105456
SL
308 fprintf(fp, "extern ");
309 ip = dp->d_vec;
310 for (;;) {
311 fprintf(fp, "X%s%d()", ip->id, dp->d_unit);
312 ip = ip->id_next;
313 if (ip == 0)
314 break;
315 fprintf(fp, ", ");
316 }
317 fprintf(fp, ";\n");
318 fprintf(fp, "int\t (*%sint%d[])() = { ", dp->d_name,
83e6c7a7 319 dp->d_unit);
a0105456
SL
320 ip = dp->d_vec;
321 for (;;) {
322 fprintf(fp, "X%s%d", ip->id, dp->d_unit);
323 ip = ip->id_next;
324 if (ip == 0)
325 break;
326 fprintf(fp, ", ");
327 }
328 fprintf(fp, ", 0 } ;\n");
dff1a390
SL
329 } else if (dp->d_type == DRIVER) /* devices w/o interrupts */
330 fprintf(fp,
331 "extern struct vba_driver %sdriver;\n",
332 dp->d_name);
b88ba334 333 }
a0105456
SL
334 fprintf(fp, "\nstruct vba_ctlr vbminit[] = {\n");
335 fprintf(fp, "/*\t driver,\tctlr,\tvbanum,\talive,\tintr,\taddr */\n");
22d68ad0 336 for (dp = dtab; dp != 0; dp = dp->d_next) {
5e794bde 337 mp = dp->d_conn;
22d68ad0 338 if (dp->d_type != CONTROLLER || mp == TO_NEXUS || mp == 0 ||
a0105456 339 !eq(mp->d_name, "vba"))
5e794bde 340 continue;
a0105456
SL
341 if (dp->d_vec == 0) {
342 printf("must specify vector for %s%d\n",
5e794bde
BJ
343 dp->d_name, dp->d_unit);
344 continue;
345 }
346 if (dp->d_addr == 0) {
347 printf("must specify csr address for %s%d\n",
348 dp->d_name, dp->d_unit);
349 continue;
350 }
351 if (dp->d_drive != UNKNOWN || dp->d_slave != UNKNOWN) {
a0105456
SL
352 printf("drives need their own entries; dont ");
353 printf("specify drive or slave for %s%d\n",
5e794bde
BJ
354 dp->d_name, dp->d_unit);
355 continue;
356 }
357 if (dp->d_flags) {
a0105456 358 printf("controllers (e.g. %s%d) ",
5e794bde 359 dp->d_name, dp->d_unit);
a0105456 360 printf("don't have flags, only devices do\n");
5e794bde
BJ
361 continue;
362 }
a0105456
SL
363 fprintf(fp,
364 "\t{ &%sdriver,\t%d,\t%s,\t0,\t%sint%d, C 0x%x },\n",
365 dp->d_name, dp->d_unit, qu(mp->d_unit),
366 dp->d_name, dp->d_unit, dp->d_addr);
b88ba334 367 }
5e794bde 368 fprintf(fp, "\t0\n};\n");
a0105456
SL
369/* versabus devices */
370 fprintf(fp, "\nstruct vba_device vbdinit[] = {\n");
5e794bde 371 fprintf(fp,
a0105456 372"\t/* driver, unit, ctlr, vbanum, slave, intr, addr, dk, flags*/\n");
22d68ad0 373 for (dp = dtab; dp != 0; dp = dp->d_next) {
5e794bde 374 mp = dp->d_conn;
22d68ad0 375 if (dp->d_unit == QUES || dp->d_type != DEVICE || mp == 0 ||
5e794bde
BJ
376 mp == TO_NEXUS || mp->d_type == MASTER ||
377 eq(mp->d_name, "mba"))
378 continue;
a0105456
SL
379 np = mp->d_conn;
380 if (np != 0 && np != TO_NEXUS && eq(np->d_name, "mba"))
381 continue;
382 np = 0;
383 if (eq(mp->d_name, "vba")) {
a6df0f0e
SL
384 if (dp->d_vec == 0)
385 printf(
386 "Warning, no interrupt vector specified for device %s%d\n",
5e794bde 387 dp->d_name, dp->d_unit);
5e794bde
BJ
388 if (dp->d_addr == 0) {
389 printf("must specify csr for device %s%d\n",
390 dp->d_name, dp->d_unit);
391 continue;
392 }
393 if (dp->d_drive != UNKNOWN || dp->d_slave != UNKNOWN) {
a0105456
SL
394 printf("drives/slaves can be specified ");
395 printf("only for controllers, ");
396 printf("not for device %s%d\n",
5e794bde
BJ
397 dp->d_name, dp->d_unit);
398 continue;
399 }
a0105456 400 vba_n = mp->d_unit;
5e794bde
BJ
401 slave = QUES;
402 } else {
a0105456
SL
403 if ((np = mp->d_conn) == 0) {
404 printf("%s%d isn't connected to anything ",
5e794bde 405 mp->d_name, mp->d_unit);
a0105456 406 printf(", so %s%d is unattached\n",
5e794bde
BJ
407 dp->d_name, dp->d_unit);
408 continue;
409 }
a0105456 410 vba_n = np->d_unit;
5e794bde 411 if (dp->d_drive == UNKNOWN) {
a0105456
SL
412 printf("must specify ``drive number'' ");
413 printf("for %s%d\n", dp->d_name, dp->d_unit);
5e794bde
BJ
414 continue;
415 }
416 /* NOTE THAT ON THE UNIBUS ``drive'' IS STORED IN */
417 /* ``SLAVE'' AND WE DON'T WANT A SLAVE SPECIFIED */
418 if (dp->d_slave != UNKNOWN) {
419 printf("slave numbers should be given only ");
420 printf("for massbus tapes, not for %s%d\n",
421 dp->d_name, dp->d_unit);
422 continue;
423 }
a0105456
SL
424 if (dp->d_vec != 0) {
425 printf("interrupt vectors should not be ");
5e794bde
BJ
426 printf("given for drive %s%d\n",
427 dp->d_name, dp->d_unit);
428 continue;
429 }
430 if (dp->d_addr != 0) {
a0105456 431 printf("csr addresses should be given only ");
5e794bde
BJ
432 printf("on controllers, not on %s%d\n",
433 dp->d_name, dp->d_unit);
434 continue;
435 }
436 slave = dp->d_drive;
437 }
a0105456
SL
438 fprintf(fp, "\t{ &%sdriver, %2d, %s,",
439 eq(mp->d_name, "vba") ? dp->d_name : mp->d_name, dp->d_unit,
440 eq(mp->d_name, "vba") ? " -1" : qu(mp->d_unit));
441 fprintf(fp, " %s, %2d, %s, C 0x%-6x, %d, 0x%x },\n",
442 qu(vba_n), slave, intv(dp), dp->d_addr, dp->d_dk,
443 dp->d_flags);
b88ba334 444 }
5e794bde 445 fprintf(fp, "\t0\n};\n");
22d68ad0 446 (void) fclose(fp);
b88ba334 447}
b312f544 448#endif
b88ba334 449
a6df0f0e
SL
450char *
451intv(dev)
5e794bde 452 register struct device *dev;
b88ba334
BJ
453{
454 static char buf[20];
455
5e794bde
BJ
456 if (dev->d_vec == 0)
457 return (" 0");
9bd38ba8
KB
458 (void) sprintf(buf, "%sint%d", dev->d_name, dev->d_unit);
459 return (buf);
b88ba334
BJ
460}
461
462char *
463qu(num)
464{
5e794bde 465
b88ba334 466 if (num == QUES)
5e794bde 467 return ("'?'");
22d68ad0 468 if (num == UNKNOWN)
5e794bde 469 return (" -1");
9bd38ba8
KB
470 (void) sprintf(errbuf, "%3d", num);
471 return (errbuf);
b88ba334 472}