xref: /original-bsd/usr.sbin/config/mkioconf.c (revision 37492ebb)
1 /*
2  * Copyright (c) 1980 Regents of the University of California.
3  * All rights reserved.
4  *
5  * %sccs.include.redist.c%
6  */
7 
8 #ifndef lint
9 static char sccsid[] = "@(#)mkioconf.c	5.21 (Berkeley) 09/07/91";
10 #endif /* not lint */
11 
12 #include <stdio.h>
13 #include "y.tab.h"
14 #include "config.h"
15 
16 /*
17  * build the ioconf.c file
18  */
19 char	*qu();
20 char	*intv();
21 char	*wnum();
22 
23 #if MACHINE_VAX
24 vax_ioconf()
25 {
26 	register struct device *dp, *mp, *np;
27 	register int uba_n, slave;
28 	FILE *fp;
29 
30 	fp = fopen(path("ioconf.c"), "w");
31 	if (fp == 0) {
32 		perror(path("ioconf.c"));
33 		exit(1);
34 	}
35 	fprintf(fp, "#include \"vax/include/pte.h\"\n");
36 	fprintf(fp, "#include \"sys/param.h\"\n");
37 	fprintf(fp, "#include \"sys/buf.h\"\n");
38 	fprintf(fp, "#include \"sys/map.h\"\n");
39 	fprintf(fp, "\n");
40 	fprintf(fp, "#include \"vax/mba/mbavar.h\"\n");
41 	fprintf(fp, "#include \"vax/uba/ubavar.h\"\n\n");
42 	fprintf(fp, "\n");
43 	fprintf(fp, "#define C (caddr_t)\n\n");
44 	/*
45 	 * First print the mba initialization structures
46 	 */
47 	if (seen_mba) {
48 		for (dp = dtab; dp != 0; dp = dp->d_next) {
49 			mp = dp->d_conn;
50 			if (mp == 0 || mp == TO_NEXUS ||
51 			    !eq(mp->d_name, "mba"))
52 				continue;
53 			fprintf(fp, "extern struct mba_driver %sdriver;\n",
54 			    dp->d_name);
55 		}
56 		fprintf(fp, "\nstruct mba_device mbdinit[] = {\n");
57 		fprintf(fp, "\t/* Device,  Unit, Mba, Drive, Dk */\n");
58 		for (dp = dtab; dp != 0; dp = dp->d_next) {
59 			mp = dp->d_conn;
60 			if (dp->d_unit == QUES || mp == 0 ||
61 			    mp == TO_NEXUS || !eq(mp->d_name, "mba"))
62 				continue;
63 			if (dp->d_addr) {
64 				printf("can't specify csr address on mba for %s%d\n",
65 				    dp->d_name, dp->d_unit);
66 				continue;
67 			}
68 			if (dp->d_vec != 0) {
69 				printf("can't specify vector for %s%d on mba\n",
70 				    dp->d_name, dp->d_unit);
71 				continue;
72 			}
73 			if (dp->d_drive == UNKNOWN) {
74 				printf("drive not specified for %s%d\n",
75 				    dp->d_name, dp->d_unit);
76 				continue;
77 			}
78 			if (dp->d_slave != UNKNOWN) {
79 				printf("can't specify slave number for %s%d\n",
80 				    dp->d_name, dp->d_unit);
81 				continue;
82 			}
83 			fprintf(fp, "\t{ &%sdriver, %d,   %s,",
84 				dp->d_name, dp->d_unit, qu(mp->d_unit));
85 			fprintf(fp, "  %s,  %d },\n",
86 				qu(dp->d_drive), dp->d_dk);
87 		}
88 		fprintf(fp, "\t0\n};\n\n");
89 		/*
90 		 * Print the mbsinit structure
91 		 * Driver Controller Unit Slave
92 		 */
93 		fprintf(fp, "struct mba_slave mbsinit [] = {\n");
94 		fprintf(fp, "\t/* Driver,  Ctlr, Unit, Slave */\n");
95 		for (dp = dtab; dp != 0; dp = dp->d_next) {
96 			/*
97 			 * All slaves are connected to something which
98 			 * is connected to the massbus.
99 			 */
100 			if ((mp = dp->d_conn) == 0 || mp == TO_NEXUS)
101 				continue;
102 			np = mp->d_conn;
103 			if (np == 0 || np == TO_NEXUS ||
104 			    !eq(np->d_name, "mba"))
105 				continue;
106 			fprintf(fp, "\t{ &%sdriver, %s",
107 			    mp->d_name, qu(mp->d_unit));
108 			fprintf(fp, ",  %2d,    %s },\n",
109 			    dp->d_unit, qu(dp->d_slave));
110 		}
111 		fprintf(fp, "\t0\n};\n\n");
112 	}
113 	/*
114 	 * Now generate interrupt vectors for the unibus
115 	 */
116 	for (dp = dtab; dp != 0; dp = dp->d_next) {
117 		if (dp->d_vec != 0) {
118 			struct idlst *ip;
119 			mp = dp->d_conn;
120 			if (mp == 0 || mp == TO_NEXUS ||
121 			    (!eq(mp->d_name, "uba") && !eq(mp->d_name, "bi")))
122 				continue;
123 			fprintf(fp,
124 			    "extern struct uba_driver %sdriver;\n",
125 			    dp->d_name);
126 			fprintf(fp, "extern ");
127 			ip = dp->d_vec;
128 			for (;;) {
129 				fprintf(fp, "X%s%d()", ip->id, dp->d_unit);
130 				ip = ip->id_next;
131 				if (ip == 0)
132 					break;
133 				fprintf(fp, ", ");
134 			}
135 			fprintf(fp, ";\n");
136 			fprintf(fp, "int\t (*%sint%d[])() = { ", dp->d_name,
137 			    dp->d_unit);
138 			ip = dp->d_vec;
139 			for (;;) {
140 				fprintf(fp, "X%s%d", ip->id, dp->d_unit);
141 				ip = ip->id_next;
142 				if (ip == 0)
143 					break;
144 				fprintf(fp, ", ");
145 			}
146 			fprintf(fp, ", 0 } ;\n");
147 		}
148 	}
149 	fprintf(fp, "\nstruct uba_ctlr ubminit[] = {\n");
150 	fprintf(fp, "/*\t driver,\tctlr,\tubanum,\talive,\tintr,\taddr */\n");
151 	for (dp = dtab; dp != 0; dp = dp->d_next) {
152 		mp = dp->d_conn;
153 		if (dp->d_type != CONTROLLER || mp == TO_NEXUS || mp == 0 ||
154 		    !eq(mp->d_name, "uba"))
155 			continue;
156 		if (dp->d_vec == 0) {
157 			printf("must specify vector for %s%d\n",
158 			    dp->d_name, dp->d_unit);
159 			continue;
160 		}
161 		if (dp->d_addr == 0) {
162 			printf("must specify csr address for %s%d\n",
163 			    dp->d_name, dp->d_unit);
164 			continue;
165 		}
166 		if (dp->d_drive != UNKNOWN || dp->d_slave != UNKNOWN) {
167 			printf("drives need their own entries; dont ");
168 			printf("specify drive or slave for %s%d\n",
169 			    dp->d_name, dp->d_unit);
170 			continue;
171 		}
172 		if (dp->d_flags) {
173 			printf("controllers (e.g. %s%d) ",
174 			    dp->d_name, dp->d_unit);
175 			printf("don't have flags, only devices do\n");
176 			continue;
177 		}
178 		fprintf(fp,
179 		    "\t{ &%sdriver,\t%d,\t%s,\t0,\t%sint%d, C 0%o },\n",
180 		    dp->d_name, dp->d_unit, qu(mp->d_unit),
181 		    dp->d_name, dp->d_unit, dp->d_addr);
182 	}
183 	fprintf(fp, "\t0\n};\n");
184 /* unibus devices */
185 	fprintf(fp, "\nstruct uba_device ubdinit[] = {\n");
186 	fprintf(fp,
187 "\t/* driver,  unit, ctlr,  ubanum, slave,   intr,    addr,    dk, flags*/\n");
188 	for (dp = dtab; dp != 0; dp = dp->d_next) {
189 		mp = dp->d_conn;
190 		if (dp->d_unit == QUES || dp->d_type != DEVICE || mp == 0 ||
191 		    mp == TO_NEXUS || mp->d_type == MASTER ||
192 		    eq(mp->d_name, "mba"))
193 			continue;
194 		np = mp->d_conn;
195 		if (np != 0 && np != TO_NEXUS && eq(np->d_name, "mba"))
196 			continue;
197 		np = 0;
198 		if (eq(mp->d_name, "uba")) {
199 			if (dp->d_vec == 0) {
200 				printf("must specify vector for device %s%d\n",
201 				    dp->d_name, dp->d_unit);
202 				continue;
203 			}
204 			if (dp->d_addr == 0) {
205 				printf("must specify csr for device %s%d\n",
206 				    dp->d_name, dp->d_unit);
207 				continue;
208 			}
209 			if (dp->d_drive != UNKNOWN || dp->d_slave != UNKNOWN) {
210 				printf("drives/slaves can be specified ");
211 				printf("only for controllers, ");
212 				printf("not for device %s%d\n",
213 				    dp->d_name, dp->d_unit);
214 				continue;
215 			}
216 			uba_n = mp->d_unit;
217 			slave = QUES;
218 		} else {
219 			if ((np = mp->d_conn) == 0) {
220 				printf("%s%d isn't connected to anything ",
221 				    mp->d_name, mp->d_unit);
222 				printf(", so %s%d is unattached\n",
223 				    dp->d_name, dp->d_unit);
224 				continue;
225 			}
226 			uba_n = np->d_unit;
227 			if (dp->d_drive == UNKNOWN) {
228 				printf("must specify ``drive number'' ");
229 				printf("for %s%d\n", dp->d_name, dp->d_unit);
230 				continue;
231 			}
232 			/* NOTE THAT ON THE UNIBUS ``drive'' IS STORED IN */
233 			/* ``SLAVE'' AND WE DON'T WANT A SLAVE SPECIFIED */
234 			if (dp->d_slave != UNKNOWN) {
235 				printf("slave numbers should be given only ");
236 				printf("for massbus tapes, not for %s%d\n",
237 				    dp->d_name, dp->d_unit);
238 				continue;
239 			}
240 			if (dp->d_vec != 0) {
241 				printf("interrupt vectors should not be ");
242 				printf("given for drive %s%d\n",
243 				    dp->d_name, dp->d_unit);
244 				continue;
245 			}
246 			if (dp->d_addr != 0) {
247 				printf("csr addresses should be given only ");
248 				printf("on controllers, not on %s%d\n",
249 				    dp->d_name, dp->d_unit);
250 				continue;
251 			}
252 			slave = dp->d_drive;
253 		}
254 		fprintf(fp, "\t{ &%sdriver,  %2d,   %s,",
255 		    eq(mp->d_name, "uba") ? dp->d_name : mp->d_name, dp->d_unit,
256 		    eq(mp->d_name, "uba") ? " -1" : qu(mp->d_unit));
257 		fprintf(fp, "  %s,    %2d,   %s, C 0%-6o,  %d,  0x%x },\n",
258 		    qu(uba_n), slave, intv(dp), dp->d_addr, dp->d_dk,
259 		    dp->d_flags);
260 	}
261 	fprintf(fp, "\t0\n};\n");
262 	(void) fclose(fp);
263 }
264 #endif
265 
266 #if MACHINE_TAHOE
267 tahoe_ioconf()
268 {
269 	register struct device *dp, *mp, *np;
270 	register int vba_n, slave;
271 	FILE *fp;
272 
273 	fp = fopen(path("ioconf.c"), "w");
274 	if (fp == 0) {
275 		perror(path("ioconf.c"));
276 		exit(1);
277 	}
278 	fprintf(fp, "#include \"sys/param.h\"\n");
279 	fprintf(fp, "#include \"tahoe/include/pte.h\"\n");
280 	fprintf(fp, "#include \"sys/buf.h\"\n");
281 	fprintf(fp, "#include \"sys/map.h\"\n");
282 	fprintf(fp, "\n");
283 	fprintf(fp, "#include \"tahoe/vba/vbavar.h\"\n");
284 	fprintf(fp, "\n");
285 	fprintf(fp, "#define C (caddr_t)\n\n");
286 	/*
287 	 * Now generate interrupt vectors for the versabus
288 	 */
289 	for (dp = dtab; dp != 0; dp = dp->d_next) {
290 		mp = dp->d_conn;
291 		if (mp == 0 || mp == TO_NEXUS || !eq(mp->d_name, "vba"))
292 			continue;
293 		if (dp->d_vec != 0) {
294 			struct idlst *ip;
295 			fprintf(fp,
296 			    "extern struct vba_driver %sdriver;\n",
297 			    dp->d_name);
298 			fprintf(fp, "extern ");
299 			ip = dp->d_vec;
300 			for (;;) {
301 				fprintf(fp, "X%s%d()", ip->id, dp->d_unit);
302 				ip = ip->id_next;
303 				if (ip == 0)
304 					break;
305 				fprintf(fp, ", ");
306 			}
307 			fprintf(fp, ";\n");
308 			fprintf(fp, "int\t (*%sint%d[])() = { ", dp->d_name,
309 			    dp->d_unit);
310 			ip = dp->d_vec;
311 			for (;;) {
312 				fprintf(fp, "X%s%d", ip->id, dp->d_unit);
313 				ip = ip->id_next;
314 				if (ip == 0)
315 					break;
316 				fprintf(fp, ", ");
317 			}
318 			fprintf(fp, ", 0 } ;\n");
319 		} else if (dp->d_type == DRIVER)  /* devices w/o interrupts */
320 			fprintf(fp,
321 			    "extern struct vba_driver %sdriver;\n",
322 			    dp->d_name);
323 	}
324 	fprintf(fp, "\nstruct vba_ctlr vbminit[] = {\n");
325 	fprintf(fp, "/*\t driver,\tctlr,\tvbanum,\talive,\tintr,\taddr */\n");
326 	for (dp = dtab; dp != 0; dp = dp->d_next) {
327 		mp = dp->d_conn;
328 		if (dp->d_type != CONTROLLER || mp == TO_NEXUS || mp == 0 ||
329 		    !eq(mp->d_name, "vba"))
330 			continue;
331 		if (dp->d_vec == 0) {
332 			printf("must specify vector for %s%d\n",
333 			    dp->d_name, dp->d_unit);
334 			continue;
335 		}
336 		if (dp->d_addr == 0) {
337 			printf("must specify csr address for %s%d\n",
338 			    dp->d_name, dp->d_unit);
339 			continue;
340 		}
341 		if (dp->d_drive != UNKNOWN || dp->d_slave != UNKNOWN) {
342 			printf("drives need their own entries; dont ");
343 			printf("specify drive or slave for %s%d\n",
344 			    dp->d_name, dp->d_unit);
345 			continue;
346 		}
347 		if (dp->d_flags) {
348 			printf("controllers (e.g. %s%d) ",
349 			    dp->d_name, dp->d_unit);
350 			printf("don't have flags, only devices do\n");
351 			continue;
352 		}
353 		fprintf(fp,
354 		    "\t{ &%sdriver,\t%d,\t%s,\t0,\t%sint%d, C 0x%x },\n",
355 		    dp->d_name, dp->d_unit, qu(mp->d_unit),
356 		    dp->d_name, dp->d_unit, dp->d_addr);
357 	}
358 	fprintf(fp, "\t0\n};\n");
359 /* versabus devices */
360 	fprintf(fp, "\nstruct vba_device vbdinit[] = {\n");
361 	fprintf(fp,
362 "\t/* driver,  unit, ctlr,  vbanum, slave,   intr,    addr,    dk, flags*/\n");
363 	for (dp = dtab; dp != 0; dp = dp->d_next) {
364 		mp = dp->d_conn;
365 		if (dp->d_unit == QUES || dp->d_type != DEVICE || mp == 0 ||
366 		    mp == TO_NEXUS || mp->d_type == MASTER ||
367 		    eq(mp->d_name, "mba"))
368 			continue;
369 		np = mp->d_conn;
370 		if (np != 0 && np != TO_NEXUS && eq(np->d_name, "mba"))
371 			continue;
372 		np = 0;
373 		if (eq(mp->d_name, "vba")) {
374 			if (dp->d_vec == 0)
375 				printf(
376 		"Warning, no interrupt vector specified for device %s%d\n",
377 				    dp->d_name, dp->d_unit);
378 			if (dp->d_addr == 0) {
379 				printf("must specify csr for device %s%d\n",
380 				    dp->d_name, dp->d_unit);
381 				continue;
382 			}
383 			if (dp->d_drive != UNKNOWN || dp->d_slave != UNKNOWN) {
384 				printf("drives/slaves can be specified ");
385 				printf("only for controllers, ");
386 				printf("not for device %s%d\n",
387 				    dp->d_name, dp->d_unit);
388 				continue;
389 			}
390 			vba_n = mp->d_unit;
391 			slave = QUES;
392 		} else {
393 			if ((np = mp->d_conn) == 0) {
394 				printf("%s%d isn't connected to anything ",
395 				    mp->d_name, mp->d_unit);
396 				printf(", so %s%d is unattached\n",
397 				    dp->d_name, dp->d_unit);
398 				continue;
399 			}
400 			vba_n = np->d_unit;
401 			if (dp->d_drive == UNKNOWN) {
402 				printf("must specify ``drive number'' ");
403 				printf("for %s%d\n", dp->d_name, dp->d_unit);
404 				continue;
405 			}
406 			/* NOTE THAT ON THE UNIBUS ``drive'' IS STORED IN */
407 			/* ``SLAVE'' AND WE DON'T WANT A SLAVE SPECIFIED */
408 			if (dp->d_slave != UNKNOWN) {
409 				printf("slave numbers should be given only ");
410 				printf("for massbus tapes, not for %s%d\n",
411 				    dp->d_name, dp->d_unit);
412 				continue;
413 			}
414 			if (dp->d_vec != 0) {
415 				printf("interrupt vectors should not be ");
416 				printf("given for drive %s%d\n",
417 				    dp->d_name, dp->d_unit);
418 				continue;
419 			}
420 			if (dp->d_addr != 0) {
421 				printf("csr addresses should be given only ");
422 				printf("on controllers, not on %s%d\n",
423 				    dp->d_name, dp->d_unit);
424 				continue;
425 			}
426 			slave = dp->d_drive;
427 		}
428 		fprintf(fp, "\t{ &%sdriver,  %2d,   %s,",
429 		    eq(mp->d_name, "vba") ? dp->d_name : mp->d_name, dp->d_unit,
430 		    eq(mp->d_name, "vba") ? " -1" : qu(mp->d_unit));
431 		fprintf(fp, "  %s,    %2d,   %s, C 0x%-6x,  %d,  0x%x },\n",
432 		    qu(vba_n), slave, intv(dp), dp->d_addr, dp->d_dk,
433 		    dp->d_flags);
434 	}
435 	fprintf(fp, "\t0\n};\n");
436 	(void) fclose(fp);
437 }
438 #endif
439 
440 #if MACHINE_HP300
441 hp300_ioconf()
442 {
443 	register struct device *dp, *mp;
444 	register int hpib, slave;
445 	FILE *fp;
446 
447 	fp = fopen(path("ioconf.c"), "w");
448 	if (fp == 0) {
449 		perror(path("ioconf.c"));
450 		exit(1);
451 	}
452 	fprintf(fp, "#include \"sys/param.h\"\n");
453 	fprintf(fp, "#include \"sys/buf.h\"\n");
454 	fprintf(fp, "#include \"sys/map.h\"\n");
455 	fprintf(fp, "\n");
456 	fprintf(fp, "#include \"hp300/dev/device.h\"\n\n");
457 	fprintf(fp, "\n");
458 	fprintf(fp, "#define C (caddr_t)\n");
459 	fprintf(fp, "#define D (struct driver *)\n\n");
460 	/*
461 	 * First print the hpib controller initialization structures
462 	 */
463 	for (dp = dtab; dp != 0; dp = dp->d_next) {
464 		mp = dp->d_conn;
465 		if (dp->d_unit == QUES || mp == 0)
466 			continue;
467 		fprintf(fp, "extern struct driver %sdriver;\n", dp->d_name);
468 	}
469 	fprintf(fp, "\nstruct hp_ctlr hp_cinit[] = {\n");
470 	fprintf(fp, "/*\tdriver,\t\tunit,\talive,\taddr,\tflags */\n");
471 	for (dp = dtab; dp != 0; dp = dp->d_next) {
472 		mp = dp->d_conn;
473 		if (dp->d_unit == QUES ||
474 			dp->d_type != MASTER && dp->d_type != CONTROLLER)
475 			continue;
476 		if (mp != TO_NEXUS) {
477 			printf("%s%s must be attached to an sc (nexus)\n",
478 				dp->d_name, wnum(dp->d_unit));
479 			continue;
480 		}
481 		if (dp->d_drive != UNKNOWN || dp->d_slave != UNKNOWN) {
482 			printf("can't specify drive/slave for %s%s\n",
483 				dp->d_name, wnum(dp->d_unit));
484 			continue;
485 		}
486 		fprintf(fp,
487 			"\t{ &%sdriver,\t%d,\t0,\tC 0x%x,\t0x%x },\n",
488 			dp->d_name, dp->d_unit, dp->d_addr, dp->d_flags);
489 	}
490 	fprintf(fp, "\t0\n};\n");
491 /* devices */
492 	fprintf(fp, "\nstruct hp_device hp_dinit[] = {\n");
493 	fprintf(fp,
494 	   "/*driver,\tcdriver,\tunit,\tctlr,\tslave,\taddr,\tdk,\tflags*/\n");
495 	for (dp = dtab; dp != 0; dp = dp->d_next) {
496 		mp = dp->d_conn;
497 		if (mp == 0 || dp->d_type != DEVICE || hpbadslave(mp, dp))
498 			continue;
499 		if (mp == TO_NEXUS) {
500 			if (dp->d_drive != UNKNOWN || dp->d_slave != UNKNOWN) {
501 				printf("can't specify drive/slave for %s%s\n",
502 					dp->d_name, wnum(dp->d_unit));
503 				continue;
504 			}
505 			slave = QUES;
506 			hpib = QUES;
507 		} else {
508 			if (dp->d_addr != 0) {
509 				printf("can't specify sc for device %s%s\n",
510 					dp->d_name, wnum(dp->d_unit));
511 				continue;
512 			}
513 			if (mp->d_type == CONTROLLER) {
514 				if (dp->d_drive == UNKNOWN) {
515 					printf("must specify drive for %s%s\n",
516 						dp->d_name, wnum(dp->d_unit));
517 					continue;
518 				}
519 				slave = dp->d_drive;
520 			} else {
521 				if (dp->d_slave == UNKNOWN) {
522 					printf("must specify slave for %s%s\n",
523 						dp->d_name, wnum(dp->d_unit));
524 					continue;
525 				}
526 				slave = dp->d_slave;
527 			}
528 			hpib = mp->d_unit;
529 		}
530 		fprintf(fp, "{ &%sdriver,\t", dp->d_name);
531 		if (mp == TO_NEXUS)
532 			fprintf(fp, "D 0x0,\t");
533 		else
534 			fprintf(fp, "&%sdriver,", mp->d_name);
535 		fprintf(fp, "\t%d,\t%d,\t%d,\tC 0x%x,\t%d,\t0x%x },\n",
536 			dp->d_unit, hpib, slave,
537 			dp->d_addr, dp->d_dk, dp->d_flags);
538 	}
539 	fprintf(fp, "0\n};\n");
540 	(void) fclose(fp);
541 }
542 
543 #define ishpibdev(n) (eq(n,"rd") || eq(n,"ct") || eq(n,"mt") || eq(n,"ppi"))
544 #define isscsidev(n) (eq(n,"sd") || eq(n,"st"))
545 
546 hpbadslave(mp, dp)
547 	register struct device *dp, *mp;
548 {
549 
550 	if (mp == TO_NEXUS && ishpibdev(dp->d_name) ||
551 	    mp != TO_NEXUS && eq(mp->d_name, "hpib") &&
552 	    !ishpibdev(dp->d_name)) {
553 		printf("%s%s must be attached to an hpib\n",
554 		       dp->d_name, wnum(dp->d_unit));
555 		return (1);
556 	}
557 	if (mp == TO_NEXUS && isscsidev(dp->d_name) ||
558 	    mp != TO_NEXUS && eq(mp->d_name, "scsi") &&
559 	    !isscsidev(dp->d_name)) {
560 		printf("%s%s must be attached to a scsi\n",
561 		       dp->d_name, wnum(dp->d_unit));
562 		return (1);
563 	}
564 	return (0);
565 }
566 #endif
567 
568 #if MACHINE_I386
569 char *sirq();
570 
571 i386_ioconf()
572 {
573 	register struct device *dp, *mp, *np;
574 	register int uba_n, slave;
575 	FILE *fp;
576 
577 	fp = fopen(path("ioconf.c"), "w");
578 	if (fp == 0) {
579 		perror(path("ioconf.c"));
580 		exit(1);
581 	}
582 	fprintf(fp, "/*\n");
583 	fprintf(fp, " * ioconf.c \n");
584 	fprintf(fp, " * Generated by config program\n");
585 	fprintf(fp, " */\n\n");
586 	fprintf(fp, "#include \"machine/pte.h\"\n");
587 	fprintf(fp, "#include \"sys/param.h\"\n");
588 	fprintf(fp, "#include \"sys/buf.h\"\n");
589 	fprintf(fp, "#include \"sys/map.h\"\n");
590 	fprintf(fp, "\n");
591 	fprintf(fp, "#define V(s)	__CONCAT(V,s)\n");
592 	fprintf(fp, "#define C (caddr_t)\n\n");
593 	/*
594 	 * First print the isa initialization structures
595 	 */
596 	if (seen_isa) {
597 
598 		fprintf(fp, "/*\n");
599 		fprintf(fp, " * ISA devices\n");
600 		fprintf(fp, " */\n\n");
601 		fprintf(fp, "#include \"i386/isa/isa_device.h\"\n");
602 		fprintf(fp, "#include \"i386/isa/isa.h\"\n");
603 		fprintf(fp, "#include \"i386/isa/icu.h\"\n\n");
604 
605 		for (dp = dtab; dp != 0; dp = dp->d_next) {
606 			mp = dp->d_conn;
607 			if (mp == 0 || mp == TO_NEXUS ||
608 			    !eq(mp->d_name, "isa"))
609 				continue;
610 			fprintf(fp,
611 "extern struct isa_driver %sdriver; extern V(%s%d)();\n",
612 			    dp->d_name, dp->d_name, dp->d_unit);
613 		}
614 		fprintf(fp, "\nstruct isa_device isa_devtab_bio[] = {\n");
615 		fprintf(fp, "\
616 /* driver 	iobase	irq   drq     maddr    msiz    intr   unit */\n");
617 		for (dp = dtab; dp != 0; dp = dp->d_next) {
618 			mp = dp->d_conn;
619 			if (dp->d_unit == QUES || mp == 0 ||
620 			    mp == TO_NEXUS || !eq(mp->d_name, "isa"))
621 				continue;
622 			if (!eq(dp->d_mask, "bio")) continue;
623 			if (dp->d_port)
624 		 fprintf(fp, "{ &%sdriver,  %8.8s,", dp->d_name, dp->d_port);
625 			else
626 	 fprintf(fp, "{ &%sdriver,     0x%03x,", dp->d_name, dp->d_portn);
627 		fprintf(fp, " %5.5s, %2d,  C 0x%05X, %5d, V(%s%d),  %2d },\n",
628 			 	sirq(dp->d_irq), dp->d_drq, dp->d_maddr,
629 			 dp->d_msize, dp->d_name, dp->d_unit, dp->d_unit);
630 		}
631 		fprintf(fp, "0\n};\n");
632 
633 		fprintf(fp, "struct isa_device isa_devtab_tty[] = {\n");
634 		fprintf(fp, "\
635 /* driver 	iobase	irq   drq     maddr    msiz    intr   unit */\n");
636 		for (dp = dtab; dp != 0; dp = dp->d_next) {
637 			mp = dp->d_conn;
638 			if (dp->d_unit == QUES || mp == 0 ||
639 			    mp == TO_NEXUS || !eq(mp->d_name, "isa"))
640 				continue;
641 			if (!eq(dp->d_mask, "tty")) continue;
642 			if (dp->d_port)
643 		 fprintf(fp, "{ &%sdriver,  %8.8s,", dp->d_name, dp->d_port);
644 			else
645 	 fprintf(fp, "{ &%sdriver,     0x%03x,", dp->d_name, dp->d_portn);
646 		fprintf(fp, " %5.5s, %2d,  C 0x%05X, %5d, V(%s%d),  %2d },\n",
647 			 	sirq(dp->d_irq), dp->d_drq, dp->d_maddr,
648 			 dp->d_msize, dp->d_name, dp->d_unit, dp->d_unit);
649 		}
650 		fprintf(fp, "0\n};\n\n");
651 
652 		fprintf(fp, "struct isa_device isa_devtab_net[] = {\n");
653 		fprintf(fp, "\
654 /* driver 	iobase	irq   drq     maddr    msiz    intr   unit */\n");
655 		for (dp = dtab; dp != 0; dp = dp->d_next) {
656 			mp = dp->d_conn;
657 			if (dp->d_unit == QUES || mp == 0 ||
658 			    mp == TO_NEXUS || !eq(mp->d_name, "isa"))
659 				continue;
660 			if (!eq(dp->d_mask, "net")) continue;
661 			if (dp->d_port)
662 		 fprintf(fp, "{ &%sdriver,  %8.8s,", dp->d_name, dp->d_port);
663 			else
664 	 fprintf(fp, "{ &%sdriver,     0x%03x,", dp->d_name, dp->d_portn);
665 		fprintf(fp, " %5.5s, %2d,  C 0x%05X, %5d, V(%s%d),  %2d },\n",
666 			 	sirq(dp->d_irq), dp->d_drq, dp->d_maddr,
667 			 dp->d_msize, dp->d_name, dp->d_unit, dp->d_unit);
668 		}
669 		fprintf(fp, "0\n};\n\n");
670 
671 		fprintf(fp, "struct isa_device isa_devtab_null[] = {\n");
672 		fprintf(fp, "\
673 /* driver 	iobase	irq   drq     maddr    msiz    intr   unit */\n");
674 		for (dp = dtab; dp != 0; dp = dp->d_next) {
675 			mp = dp->d_conn;
676 			if (dp->d_unit == QUES || mp == 0 ||
677 			    mp == TO_NEXUS || !eq(mp->d_name, "isa"))
678 				continue;
679 			if (!eq(dp->d_mask, "null")) continue;
680 			if (dp->d_port)
681 		 fprintf(fp, "{ &%sdriver,  %8.8s,", dp->d_name, dp->d_port);
682 			else
683 	 fprintf(fp, "{ &%sdriver,     0x%03x,", dp->d_name, dp->d_portn);
684 		fprintf(fp, " %5.5s, %2d,  C 0x%05X, %5d, V(%s%d),  %2d },\n",
685 			 	sirq(dp->d_irq), dp->d_drq, dp->d_maddr,
686 			 dp->d_msize, dp->d_name, dp->d_unit, dp->d_unit);
687 		}
688 		fprintf(fp, "0\n};\n\n");
689 	}
690 	(void) fclose(fp);
691 }
692 
693 char *
694 sirq(num)
695 {
696 
697 	if (num == -1)
698 		return ("0");
699 	sprintf(errbuf, "IRQ%d", num);
700 	return (errbuf);
701 }
702 #endif
703 
704 #if MACHINE_PMAX
705 pmax_ioconf()
706 {
707 	register struct device *dp, *mp;
708 	FILE *fp;
709 
710 	fp = fopen(path("ioconf.c"), "w");
711 	if (fp == 0) {
712 		perror(path("ioconf.c"));
713 		exit(1);
714 	}
715 	fprintf(fp, "#include \"types.h\"\n");
716 	fprintf(fp, "#include \"pmax/dev/device.h\"\n\n");
717 	fprintf(fp, "#define C (char *)\n\n");
718 
719 	/* print controller initialization structures */
720 	for (dp = dtab; dp != 0; dp = dp->d_next) {
721 		if (dp->d_type == PSEUDO_DEVICE)
722 			continue;
723 		fprintf(fp, "extern struct driver %sdriver;\n", dp->d_name);
724 	}
725 	fprintf(fp, "\nstruct pmax_ctlr pmax_cinit[] = {\n");
726 	fprintf(fp, "/*\tdriver,\t\tunit,\taddr,\t\tflags */\n");
727 	for (dp = dtab; dp != 0; dp = dp->d_next) {
728 		if (dp->d_type != CONTROLLER && dp->d_type != MASTER)
729 			continue;
730 		if (dp->d_conn != TO_NEXUS) {
731 			printf("%s%s must be attached to a nexus (internal bus)\n",
732 				dp->d_name, wnum(dp->d_unit));
733 			continue;
734 		}
735 		if (dp->d_drive != UNKNOWN || dp->d_slave != UNKNOWN) {
736 			printf("can't specify drive/slave for %s%s\n",
737 				dp->d_name, wnum(dp->d_unit));
738 			continue;
739 		}
740 		if (dp->d_unit == UNKNOWN || dp->d_unit == QUES)
741 			dp->d_unit = 0;
742 		fprintf(fp,
743 			"\t{ &%sdriver,\t%d,\tC 0x%x,\t0x%x },\n",
744 			dp->d_name, dp->d_unit, dp->d_addr, dp->d_flags);
745 	}
746 	fprintf(fp, "\t0\n};\n");
747 
748 	/* print devices connected to other controllers */
749 	fprintf(fp, "\nstruct scsi_device scsi_dinit[] = {\n");
750 	fprintf(fp,
751 	   "/*driver,\tcdriver,\tunit,\tctlr,\tdrive,\tslave,\tdk,\tflags*/\n");
752 	for (dp = dtab; dp != 0; dp = dp->d_next) {
753 		if (dp->d_type == CONTROLLER || dp->d_type == MASTER ||
754 		    dp->d_type == PSEUDO_DEVICE)
755 			continue;
756 		mp = dp->d_conn;
757 		if (mp == 0 || !eq(mp->d_name, "sii")) {
758 			printf("%s%s: devices must be attached to a SCSI (sii) controller\n",
759 				dp->d_name, wnum(dp->d_unit));
760 			continue;
761 		}
762 		if ((unsigned)dp->d_drive > 6) {
763 			printf("%s%s: SCSI drive must be in the range 0..6\n",
764 				dp->d_name, wnum(dp->d_unit));
765 			continue;
766 		}
767 		/* may want to allow QUES later */
768 		if ((unsigned)dp->d_slave > 7) {
769 			printf("%s%s: SCSI slave (LUN) must be in the range 0..7\n",
770 				dp->d_name, wnum(dp->d_unit));
771 			continue;
772 		}
773 		fprintf(fp, "{ &%sdriver,\t&%sdriver,", dp->d_name, mp->d_name);
774 		fprintf(fp, "\t%d,\t%d,\t%d,\t%d,\t%d,\t0x%x },\n",
775 			dp->d_unit, mp->d_unit, dp->d_drive, dp->d_slave,
776 			dp->d_dk, dp->d_flags);
777 	}
778 	fprintf(fp, "0\n};\n");
779 	(void) fclose(fp);
780 }
781 #endif
782 
783 char *
784 intv(dev)
785 	register struct device *dev;
786 {
787 	static char buf[20];
788 
789 	if (dev->d_vec == 0)
790 		return ("     0");
791 	(void) sprintf(buf, "%sint%d", dev->d_name, dev->d_unit);
792 	return (buf);
793 }
794 
795 char *
796 qu(num)
797 {
798 
799 	if (num == QUES)
800 		return ("'?'");
801 	if (num == UNKNOWN)
802 		return (" -1");
803 	(void) sprintf(errbuf, "%3d", num);
804 	return (errbuf);
805 }
806 
807 char *
808 wnum(num)
809 {
810 
811 	if (num == QUES || num == UNKNOWN)
812 		return ("?");
813 	(void) sprintf(errbuf, "%d", num);
814 	return (errbuf);
815 }
816