Annotation of researchv9/sys.vax/conf/src/config/mkioconf.c, revision 1.1

1.1     ! root        1: #include <stdio.h>
        !             2: #include "y.tab.h"
        !             3: #include "config.h"
        !             4: 
        !             5: /*
        !             6:  * mkioconf.c  1.9     81/07/09
        !             7:  * ioconf:
        !             8:  *     Build the ioconf.c file
        !             9:  */
        !            10: char *qu();
        !            11: 
        !            12: ioconf()
        !            13: {
        !            14:     register struct device *dp, *mp, *np;
        !            15:     register int uba_n, slave;
        !            16:     char *intv();
        !            17:     FILE *fp;
        !            18: 
        !            19:     fp = fopen(LOCAL("ioconf.c"), "w");
        !            20:     if (fp == NULL) {
        !            21:        perror(LOCAL("ioconf.c"));
        !            22:        exit(1);
        !            23:     }
        !            24:     fprintf(fp, "#include \"../h/param.h\"\n");
        !            25:     fprintf(fp, "#include \"../h/pte.h\"\n");
        !            26:     fprintf(fp, "#include \"../h/buf.h\"\n");
        !            27:     fprintf(fp, "#include \"../h/map.h\"\n");
        !            28:     fprintf(fp, "#include \"../h/mbavar.h\"\n");
        !            29:     fprintf(fp, "#include \"../h/vm.h\"\n");
        !            30:     fprintf(fp, "#include \"../h/ubavar.h\"\n\n");
        !            31:     fprintf(fp, "#define C (caddr_t)\n\n");
        !            32:     /*
        !            33:      * First print the mba initialization structures
        !            34:      */
        !            35:     if (seen_mba)
        !            36:     {
        !            37:        for (dp = dtab; dp != NULL; dp = dp->d_next)
        !            38:        {
        !            39:            mp = dp->d_conn;
        !            40:            if (mp == NULL || mp == TO_NEXUS || !eq(mp->d_name, "mba"))
        !            41:                continue;
        !            42:            fprintf(fp, "extern struct mba_driver %sdriver;\n", dp->d_name);
        !            43:        }
        !            44:        fprintf(fp, "\nstruct mba_device mbdinit[] = {\n");
        !            45:        fprintf(fp, "\t/* Device,  Unit, Mba, Drive, Dk */\n");
        !            46:        for (dp = dtab; dp != NULL; dp = dp->d_next)
        !            47:        {
        !            48:            mp = dp->d_conn;
        !            49:            if (dp->d_unit == QUES || mp == NULL || mp == TO_NEXUS || !eq(mp->d_name, "mba"))
        !            50:                continue;
        !            51:            if (dp->d_addr) {
        !            52:                printf("can't specify csr address on mba for %s%d\n",
        !            53:                    dp->d_name, dp->d_unit);
        !            54:                continue;
        !            55:            }
        !            56:            if (dp->d_vec != NULL) {
        !            57:                printf("can't specify vector for %s%d on mba\n",
        !            58:                        dp->d_name, dp->d_unit);
        !            59:                continue;
        !            60:            }
        !            61:            if (dp->d_drive == UNKNOWN) {
        !            62:                printf("drive not specified for %s%d\n",
        !            63:                    dp->d_name, dp->d_unit);
        !            64:                continue;
        !            65:            }
        !            66:            if (dp->d_slave != UNKNOWN) {
        !            67:                printf("can't specify slave number for %s%d\n", 
        !            68:                    dp->d_name, dp->d_unit);
        !            69:                continue;
        !            70:            }
        !            71:            fprintf(fp, "\t{ &%sdriver, %d,   %s,  %s,    %d },\n",
        !            72:                dp->d_name, dp->d_unit, qu(mp->d_unit),
        !            73:                qu(dp->d_drive), dp->d_dk);
        !            74:        }
        !            75:        fprintf(fp, "\t0\n};\n\n");
        !            76:        /*
        !            77:         * Print the mbsinit structure
        !            78:         * Driver Controller Unit Slave
        !            79:         */
        !            80:        fprintf(fp, "struct mba_slave mbsinit [] = {\n");
        !            81:        fprintf(fp, "\t/* Driver,  Ctlr, Unit, Slave */\n");
        !            82:        for (dp = dtab; dp != NULL; dp = dp->d_next)
        !            83:        {
        !            84:            /*
        !            85:             * All slaves are connected to something which is connected to
        !            86:             * the massbus.
        !            87:             */
        !            88:            if ((mp = dp->d_conn) == NULL || mp == TO_NEXUS)
        !            89:                continue;
        !            90:            np = mp->d_conn;
        !            91:            if (np == NULL || np == TO_NEXUS || !eq(np->d_name, "mba"))
        !            92:                continue;
        !            93:            fprintf(fp, "\t{ &%sdriver, %s,  %2d,    %d },\n",
        !            94:                mp->d_name, qu(mp->d_unit), dp->d_unit, dp->d_slave);
        !            95:        }
        !            96:        fprintf(fp, "\t0\n};\n\n");
        !            97:     }
        !            98:     /*
        !            99:      * Now generate interrupt vectors for the unibus
        !           100:      */
        !           101:     for (dp = dtab; dp != NULL; dp = dp->d_next) {
        !           102:        if (dp->d_vec != NULL) {
        !           103:            struct idlst *ip;
        !           104:            mp = dp->d_conn;
        !           105:            if (mp == NULL || mp == TO_NEXUS || !eq(mp->d_name, "uba"))
        !           106:                continue;
        !           107:            fprintf(fp, "extern struct uba_driver %sdriver;\n", dp->d_name);
        !           108:            fprintf(fp, "extern ");
        !           109:            ip = dp->d_vec;
        !           110:            for (;;) {
        !           111:                fprintf(fp, "X%s%d()", ip->id, dp->d_unit);
        !           112:                ip = ip->id_next;
        !           113:                if (ip == 0)
        !           114:                    break;
        !           115:                fprintf(fp, ", ");
        !           116:            }
        !           117:            fprintf(fp, ";\n");
        !           118:            fprintf(fp, "int\t (*%sint%d[])() = { ", dp->d_name, dp->d_unit);
        !           119:            ip = dp->d_vec;
        !           120:            for (;;) {
        !           121:                fprintf(fp, "X%s%d", ip->id, dp->d_unit);
        !           122:                ip = ip->id_next;
        !           123:                if (ip == 0)
        !           124:                    break;
        !           125:                fprintf(fp, ", ");
        !           126:            }
        !           127:            fprintf(fp, ", 0 } ;\n");
        !           128:        }
        !           129:     }
        !           130:     /*
        !           131:      * Now spew forth the uba_minfo structure
        !           132:      */
        !           133:     fprintf(fp, "\nstruct uba_ctlr ubminit[] = {\n");
        !           134:     fprintf(fp, "/*\t driver,\tctlr,\tubanum,\talive,\tintr,\taddr */\n");
        !           135:     for (dp = dtab; dp != NULL; dp = dp->d_next) {
        !           136:        mp = dp->d_conn;
        !           137:        if (dp->d_type != CONTROLLER || mp == TO_NEXUS || mp == NULL || !eq(mp->d_name, "uba"))
        !           138:            continue;
        !           139:        if (dp->d_vec == 0) {
        !           140:            printf("must specify vector for %s%d\n", dp->d_name, dp->d_unit);
        !           141:            continue;
        !           142:        }
        !           143:        if (dp->d_addr == 0) {
        !           144:            printf("must specify csr address for %s%d\n",
        !           145:                dp->d_name, dp->d_unit);
        !           146:            continue;
        !           147:        }
        !           148:        if (dp->d_drive != UNKNOWN || dp->d_slave != UNKNOWN) {
        !           149:            printf("drives need their own entries; dont specify drive or slave for %s%d\n",
        !           150:                dp->d_name, dp->d_unit);
        !           151:            continue;
        !           152:        }
        !           153:        if (dp->d_flags) {
        !           154:            printf("controllers (e.g. %s%d) don't have flags, only devices do\n",
        !           155:                dp->d_name, dp->d_unit);
        !           156:            continue;
        !           157:        }
        !           158:        fprintf(fp, "\t{ &%sdriver,\t%d,\t%s,\t0,\t%sint%d, C 0%o },\n",
        !           159:            dp->d_name, dp->d_unit, qu(mp->d_unit),
        !           160:            dp->d_name, dp->d_unit, dp->d_addr);
        !           161:     }
        !           162:     fprintf(fp, "\t0\n};\n");
        !           163:     /*
        !           164:      * Now we go for the uba_device stuff
        !           165:      */
        !           166:     fprintf(fp, "\nstruct uba_device ubdinit[] = {\n");
        !           167:     fprintf(fp, "\t/* driver,  unit, ctlr,  ubanum, slave,   intr,    addr,    dk, flags*/\n");
        !           168:     for (dp = dtab; dp != NULL; dp = dp->d_next) {
        !           169:        mp = dp->d_conn;
        !           170:        if (dp->d_unit == QUES || dp->d_type != DEVICE || mp == NULL ||
        !           171:                mp == TO_NEXUS || mp->d_type == MASTER || eq(mp->d_name, "mba"))
        !           172:            continue;
        !           173:         np = mp->d_conn;
        !           174:         if (np != NULL && np != TO_NEXUS && eq(np->d_name, "mba"))
        !           175:            continue;
        !           176:        np = NULL;
        !           177:        if (eq(mp->d_name, "uba")) {
        !           178:            if (dp->d_vec == 0) {
        !           179:                printf("must specify vector for device %s%d\n",
        !           180:                    dp->d_name, dp->d_unit);
        !           181:                continue;
        !           182:            }
        !           183:            if (dp->d_addr == 0) {
        !           184:                printf("must specify csr address for device %s%d\n",
        !           185:                    dp->d_name, dp->d_unit);
        !           186:                continue;
        !           187:            }
        !           188:            if (dp->d_drive != UNKNOWN || dp->d_slave != UNKNOWN) {
        !           189:                printf("drives/slaves can be specified only for controllers, not for device %s%d\n",
        !           190:                    dp->d_name, dp->d_unit);
        !           191:                continue;
        !           192:            }
        !           193:            uba_n = mp->d_unit;
        !           194:            slave = QUES;
        !           195:        } else {
        !           196:            if ((np = mp->d_conn) == NULL) {
        !           197:                printf("%s%d isn't connected to anything, so %s%d is unattached\n",
        !           198:                    mp->d_name, mp->d_unit, dp->d_name, dp->d_unit);
        !           199:                continue;
        !           200:            }
        !           201:            uba_n = np->d_unit;
        !           202:            if (dp->d_drive == UNKNOWN) {
        !           203:                printf("must specify ``drive number'' for %s%d\n",
        !           204:                   dp->d_name, dp->d_unit);
        !           205:                continue;
        !           206:            }
        !           207:            /* NOTE THAT ON THE UNIBUS ``drive'' IS STORED IN */
        !           208:            /* ``SLAVE'' AND WE DON'T WANT A SLAVE SPECIFIED */
        !           209:            if (dp->d_slave != UNKNOWN) {
        !           210:                printf("slave numbers should be given only for massbus tapes, not for %s%d\n",
        !           211:                    dp->d_name, dp->d_unit);
        !           212:                continue;
        !           213:            }
        !           214:            if (dp->d_vec != 0) {
        !           215:                printf("interrupt vectors should not be given for drive %s%d\n",
        !           216:                    dp->d_name, dp->d_unit);
        !           217:                continue;
        !           218:            }
        !           219:            if (dp->d_addr != 0) {
        !           220:                printf("csr addresses should be given only on controllers, not on %s%d\n",
        !           221:                    dp->d_name, dp->d_unit);
        !           222:                continue;
        !           223:            }
        !           224:            slave = dp->d_drive;
        !           225:        }
        !           226:        fprintf(fp, "\t{ &%sdriver,  %2d,   %s,  %s,    %2d,   %s, C 0%-6o,  %d,  0x%x },\n",
        !           227:            eq(mp->d_name, "uba") ? dp->d_name : mp->d_name, dp->d_unit,
        !           228:            eq(mp->d_name, "uba") ? " -1" : qu(mp->d_unit), qu(uba_n),
        !           229:            slave, intv(dp), dp->d_addr, dp->d_dk, dp->d_flags);
        !           230:     }
        !           231:     fprintf(fp, "\t0\n};\n");
        !           232:     fclose(fp);
        !           233: }
        !           234: 
        !           235: /*
        !           236:  * intv
        !           237:  *     Return vector name
        !           238:  */
        !           239: 
        !           240: char *intv(dev)
        !           241: register struct device *dev;
        !           242: {
        !           243:        static char buf[20];
        !           244: 
        !           245:        if (dev->d_vec == NULL)
        !           246:            return "     0";
        !           247:        else {
        !           248:            sprintf(buf, "%sint%d", dev->d_name, dev->d_unit);
        !           249:            return buf;
        !           250:        }
        !           251: }
        !           252: 
        !           253: char *
        !           254: qu(num)
        !           255: {
        !           256:        if (num == QUES)
        !           257:                return "'?'";
        !           258:        if(num == UNKNOWN)
        !           259:                return " -1";
        !           260:        sprintf(errbuf, "%3d", num);
        !           261:        return ns(errbuf);
        !           262: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.