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