Annotation of cci/usr/src/usr.bin/cdb/transBsd/main.c, revision 1.1.1.1

1.1       root        1: /* $Header: main.c,v 1.1 86/03/24 16:19:20 rcs Exp $ */
                      2: /* (C) Copyright 1985 Third Eye Software, Inc. - All Rights Reserved */
                      3: 
                      4: #include "tes42.h"
                      5: 
                      6: #include <sys/file.h>
                      7: #include <stab.h>
                      8: 
                      9: /* indexes */
                     10: export int     vissMac, vissMax;
                     11: export int     vifd, vifdMac;                  /* vrgFd */
                     12: export int     vipdMac, vipd;                  /* vrgPd */
                     13: export int     viline, vilineMac = 1;          /* vrgLine */
                     14: export int     visym, visymMac = 1;            /* vrgSym */
                     15: export int     visymGlobal, visymGlMac, visymGlMax;
                     16: export int     viauxMac, viaux;                /* vrgAux */
                     17: export int     vites42Max = tesF42Low;         /* vrgTesF42 */
                     18: 
                     19: /* flags */
                     20: export int     vfBlockPending;                 /* true if got local */
                     21: export int     vfVerbose;                      /* true if we want text out */
                     22: export int     vfWarn;                         /* give certain warnings */
                     23: 
                     24: export int     vcLinesInProc;                  /* count of lines in cur proc */
                     25: 
                     26: /* tables */
                     27: export char    *vsbNewStr;                     /* new string table */
                     28: export int     vadjust = 1;                    /* forces bigger tables */
                     29: export pAUXU   vrgAux;                         /* aux table */
                     30: export pPDR    vrgPd;                          /* proc table */
                     31: export pFDR    vrgFd;                          /* file table */
                     32: export pLINER  vrgLine;                        /* line no table */
                     33: export pSYMR   vrgSym;                         /* symbol table */
                     34: export pSYMR   vrgSymGlobal;                   /* global symbol table */
                     35: export pSYMR   vrgSymBrac[100];                /* block stack for RBRAC's */
                     36: export int     *vrgTesF42;                     /* map 42 no's to tes aux's */
                     37: 
                     38: /* pointers */
                     39: export char    *vsbType;                       /* points to cur type string */
                     40: export char    *vsbMax;                        /* next avail. in vsbNewStr */
                     41: export pSYMR   vsymProc;                       /* current proc symbol */
                     42: export pSYMR   vsymBlock;                      /* block sym when pending */
                     43: export pSYMR   vsymFile;                       /* current file */
                     44: export int     vfdSym;                         /* channel of sym file */
                     45: export long    vdot;                   /* last known adr in TEXT space */
                     46: export int     vissTag;                        /* iss for tag type */
                     47: 
                     48: export HDRR    vahdr;
                     49: 
                     50: /* kludges */
                     51: export int viauxProcPhony;                     /* something for phony procs */
                     52: export int viauxGlobalPhony;           /* something for unknown globals */
                     53: 
                     54: /* KLUDGE for SUN!! */
                     55: export pNLISTR vnlist;
                     56: 
                     57: 
                     58: /* M A I N */
                     59: 
                     60: main(argc, argv) 
                     61: int     argc;
                     62: char    *argv [];
                     63: {
                     64:     char       *sbFile = (char *) 0;
                     65: 
                     66:     argv++;
                     67:     while (--argc) {
                     68: 
                     69:        if (*argv [0] == '-') {
                     70:            switch (argv [0] [1]) {
                     71:                case 's':
                     72:                    vadjust = atoi(argv[0]+2);
                     73:                    if ((vadjust <= 0) || (vadjust > 10)) {
                     74:                        printf("Bad scaling parameter: %d\n", vadjust);
                     75:                        exit(1);
                     76:                    } /* if */
                     77:                    argv++;
                     78:                    continue;
                     79:                case 'v':
                     80:                    vfVerbose++;
                     81:                    argv++;
                     82:                    continue;
                     83:                case 'w':
                     84:                    vfWarn++;
                     85:                    argv++;
                     86:                    continue;
                     87:                default:
                     88:                    panic("illegal option");
                     89:            } /* switch */
                     90:        } else {
                     91:            if (sbFile)
                     92:                panic("only one filename allowed");
                     93:            sbFile = argv [0];
                     94:            argv++;
                     95:        }
                     96:     } /* while */
                     97: 
                     98:     if (sbFile == (char *) 0)
                     99:        sbFile = "a.out";
                    100: 
                    101:     Sym42Init(sbFile);
                    102:     AuxBtInit();
                    103:     Map();
                    104:     DumpAll(sbFile);
                    105:     if (vfVerbose)
                    106:        PrintAll();
                    107:     exit(0);
                    108: } /* main */
                    109: 
                    110: 
                    111: /* M A P */
                    112: 
                    113: export void Map()
                    114: {
                    115:     SYMR               asym;
                    116:     register pSYMR     sym;
                    117:     register pSYMR     sym1;
                    118:     register int       tq;
                    119:     int                        fFirstGlobal;
                    120:     int                        isymType, sc, st, iss;
                    121:     register char      *sbName;
                    122:     int                        cbName;
                    123:     pFDR               fd;
                    124:     pPDR               pd;
                    125:     static TIR         ati;
                    126: 
                    127:     fFirstGlobal = true;
                    128:     vnlist = (pNLISTR) malloc(vcsym * cbNLISTR);
                    129:     if (vnlist == nlistNil) {
                    130:        perror("allocation for symbol table");
                    131:        exit(1);
                    132:     } /* if */
                    133: 
                    134:     if (read(vfdSym, vnlist, cbNLISTR * vcsym) != cbNLISTR * vcsym) {
                    135:        perror("symbol read");
                    136:        exit(1);
                    137:     } /* if */
                    138: 
                    139:     /* build something for phony procedures to point at */
                    140:     viauxProcPhony = AddAux(isymNil);
                    141:     ati.tq0 = tqProc;
                    142:     ati.bt = btInt;
                    143:     AddAux(ati);
                    144:     viauxGlobalPhony = AddAux(AuxFBType(btInt));
                    145: 
                    146:     DoFile(nlistNil, "temp");
                    147:     while (vcsym--) {
                    148:        sbName = vsbStr + vnlist->n_un.n_strx;
                    149: 
                    150:        /* the following code to process loader symbols depends
                    151:         *      on their occuring after symbol table symbols in
                    152:         *      the bsd42 symbol table.
                    153:         */
                    154:        sc = scNil;
                    155:        st = stNil;
                    156: 
                    157:        switch (vnlist->n_type) {
                    158: 
                    159:            case N_TEXT:
                    160:                cbName = strlen(sbName);
                    161:                if (sbName[cbName - 1] == 'o' && sbName[cbName - 2] == '.') {
                    162:                    DoFile(vnlist, sbName);
                    163:                    vnlist++;
                    164:                    continue;
                    165:                } else if (sbName[0] == '-'
                    166:                        && sbName[1] == 'l'
                    167:                        && sbName[2] == 'g') {
                    168:                    DoFile(vnlist, sbName);
                    169:                    vnlist++;
                    170:                    continue;
                    171:                } else {
                    172:                    sc = scText;
                    173:                    st = stLabel;
                    174:                    goto llocal;
                    175:                } /* if */
                    176:            case N_DATA:
                    177:                sc = scData;
                    178:                st = stGlobal;
                    179:                goto llocal;
                    180:            case N_ABS:
                    181:                break;  /* for now we throw them away */
                    182:                /* sc = scAbs;
                    183:                 * goto llocal;
                    184:                 */
                    185:            case N_BSS:
                    186:                sc = scBss;
                    187:                st = stGlobal;
                    188: llocal:
                    189:                if (*sbName == '_') sbName++;
                    190:                iss = IssFSbInsert(sbName);
                    191:                if (!ExistingFdSymFIss(iss)) {
                    192:                    sym = SymFInsert();
                    193:                    sym->sc = sc;
                    194:                    sym->st = st;
                    195:                    sym->value = vnlist->n_value;
                    196:                    sym->iss = iss;
                    197:                    sym->index = viauxGlobalPhony;
                    198:                } /* if */
                    199:                vnlist++;
                    200:                continue;
                    201: 
                    202:            case N_EXT+N_TEXT:
                    203:                if (vsymProc) {
                    204:                    /* there was a previous proc, so end it */
                    205:                    sym = SymFInsert();
                    206:                    sym->st = stEnd;
                    207:                    sym->sc = scText;
                    208:                    sym->index = IsymFSym(vsymProc);
                    209:                    sym->value = vdot;  /* last know text adr */
                    210:                    ChangeAux(vsymProc->index, visym);
                    211:                    vsymProc = symNil;
                    212:                } /* if */
                    213: 
                    214:                asym.sc = scText;
                    215:                if (*sbName == '_') sbName++;
                    216:                asym.iss = IssFSbInsert(sbName);
                    217:                if ((sym = ExistingSymFSbProc(asym.iss)) != symNil) {
                    218:                    if (!sym->sc)
                    219:                        sym->sc = asym.sc;
                    220:                } else {
                    221:                    sym = SymFInsert();
                    222:                    sym->sc = asym.sc;
                    223:                    sym->st = stProc;
                    224:                    sym->index = viauxProcPhony;
                    225:                    sym->iss = asym.iss;
                    226:                    ProcInsert(IsymFSym(sym), vnlist->n_value, 0);
                    227:                } /* if */
                    228:                sym->value = vnlist->n_value;
                    229:                vnlist++;
                    230:                continue;
                    231: 
                    232:            case N_EXT+N_DATA:
                    233:                asym.sc = scData;
                    234:                asym.st = stGlobal;
                    235:                goto ldoexternal;
                    236:            case N_EXT+N_ABS:
                    237:                asym.sc = scAbs;
                    238:                goto ldoexternal;
                    239:            case N_EXT+N_BSS:
                    240:                asym.sc = scBss;
                    241:                asym.st = stGlobal;
                    242: ldoexternal:
                    243:                if (*sbName == '_')
                    244:                    sbName++;
                    245:                asym.iss = IssFSbInsert(sbName);
                    246:                if ((sym = ExistingSymFGlobal(&asym)) != symNil) {
                    247:                    if (!sym->sc)
                    248:                        sym->sc = asym.sc;
                    249:                } else {
                    250:                    if (fFirstGlobal) {
                    251:                        EndFile(vdot);
                    252:                        fFirstGlobal = false;
                    253:                    } /* if */
                    254:                    sym = SymFGlobal();
                    255:                    sym->sc = asym.sc;
                    256:                    sym->iss = asym.iss;
                    257:                    sym->index = viauxGlobalPhony;
                    258:                } /* if */
                    259:                sym->value = vnlist->n_value;
                    260:                sym->st = asym.st;
                    261:                vnlist++;
                    262:                continue;
                    263: 
                    264:            case N_SLINE:
                    265:                DoLine(vnlist);
                    266:                vnlist++;
                    267:                continue;
                    268: 
                    269:            case N_SOL:
                    270:                vnlist++;
                    271:                continue;
                    272: 
                    273:            case N_SO:
                    274:                DoFile(vnlist, sbName);
                    275:                vnlist++;
                    276:                continue;
                    277: 
                    278:            case N_LBRAC:
                    279:                DoLBrac(vnlist);
                    280:                vnlist++;
                    281:                continue;
                    282: 
                    283:            case N_RBRAC:
                    284:                DoRBrac(vnlist);
                    285:                vnlist++;
                    286:                continue;
                    287: 
                    288:            default:
                    289:                DoSym(vnlist, sbName);
                    290: 
                    291:        } /* switch */
                    292: 
                    293:        vnlist++;
                    294:     } /*while */
                    295: 
                    296:     /* fix the damn fd's, ya happy GFW? */
                    297:     vrgFd[0].ipd = -1;
                    298:     vrgFd[0].iline = 0;
                    299:     for (fd = vrgFd+1, pd = vrgPd; fd < vrgFd+vifdMac; fd++) {
                    300:        while ((pd < vrgPd+vipdMac) && (fd->adr > pd->adr))
                    301:            pd++;
                    302:        fd->ipd = pd - vrgPd;
                    303:        if (vrgSym[pd->isym].index == viauxProcPhony)
                    304:            pd->iline = 0;
                    305:        fd->iline = pd->iline;  /* is this always correct? */
                    306:     } /* for */
                    307: } /* Map */
                    308: 
                    309: 
                    310: /* D U M P   A L L */
                    311: 
                    312: export void DumpAll(sbFile)
                    313: char   *sbFile;
                    314: {
                    315:     char       sbTes[200];
                    316:     int                cGlobals, file;
                    317:     long       cbOffset;
                    318:     extern struct exec vhead;
                    319: 
                    320:     strcpy(sbTes, sbFile);
                    321:     strcat(sbTes, ".cdb");
                    322: 
                    323:     vahdr.magic = vhead.a_magic;
                    324:     vahdr.vstamp = 0;
                    325:     vahdr.ijokeDay = ijokeNil;
                    326:     vahdr.cbText = vhead.a_text;
                    327:     vahdr.cbData = vhead.a_data;
                    328:     vahdr.cbBss = vhead.a_bss;
                    329:     vahdr.entrypoint = vhead.a_entry;
                    330: 
                    331: 
                    332:     if ((file = open(sbTes, O_WRONLY+O_CREAT, 0666)) <= -1) {
                    333:        perror("can't open output file");
                    334:        exit(1);
                    335:     } /* if */
                    336: 
                    337: #define WRITE_IT(fd,buf,size,count,msg) \
                    338:     if (write(fd, buf, (size) * (count)) != (size) * (count)) {\
                    339:            perror(msg);\
                    340:            exit(1);\
                    341:     } else {\
                    342:        cbOffset += (size) * (count);\
                    343:     } /* if */
                    344: 
                    345:     cbOffset = 0;
                    346:     WRITE_IT(file, &vahdr, cbHDRR, 1, "header")
                    347: 
                    348:     vahdr.ipdMax = vipdMac;
                    349:     vahdr.cbPdOffset = cbOffset;
                    350:     WRITE_IT(file, vrgPd, cbPDR, vipdMac, "procedures")
                    351: 
                    352:     vahdr.ifdMax = vifdMac;
                    353:     vahdr.cbFdOffset = cbOffset;
                    354:     WRITE_IT(file, vrgFd, cbFDR, vifdMac, "files")
                    355: 
                    356:     vahdr.ilineMax = vilineMac;
                    357:     vahdr.cbLineOffset = cbOffset;
                    358:     WRITE_IT(file, vrgLine, cbLINER, vilineMac, "lines")
                    359: 
                    360:     vahdr.iauxMax = viauxMac;
                    361:     vahdr.cbAuxOffset = cbOffset;
                    362:     WRITE_IT(file, vrgAux, cbAUXU, viauxMac, "auxes")
                    363: 
                    364:     vahdr.isymGl = visymMac;
                    365:     vahdr.isymGlMax = vahdr.isymMax = visymMac + visymGlMac;
                    366:     vahdr.cbSymOffset = cbOffset;
                    367:     WRITE_IT(file, vrgSym, cbSYMR, visymMac, "symbols")
                    368:     WRITE_IT(file, vrgSymGlobal, cbSYMR, visymGlMac, "globals")
                    369: 
                    370:     vahdr.issMax = vissMac;
                    371:     vahdr.cbSsOffset = cbOffset;
                    372:     WRITE_IT(file, vsbNewStr, vissMac, 1, "strings");
                    373: 
                    374:     lseek(file, 0L, 0);
                    375:     WRITE_IT(file, &vahdr, cbHDRR, 1, "header")
                    376: } /* DumpAll */

unix.superglobalmegacorp.com

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