Annotation of researchv10no/cmd/adb/cray/setup.c, revision 1.1

1.1     ! root        1: /*
        !             2:  * adb - routines to read a.out+core at startup
        !             3:  * this for cray; very simple, but some hooks left for later
        !             4:  */
        !             5: #include "defs.h"
        !             6: /*
        !             7:  * beware!
        !             8:  */
        !             9: #undef wtoa
        !            10: #undef atow
        !            11: #undef wtoc
        !            12: #undef ctow
        !            13: #include "space.h"
        !            14: #include "map.h"
        !            15: #include "machine.h"
        !            16: #include <sys/param.h>
        !            17: #include <sys/types.h>
        !            18: #include <sys/sysmacros.h>
        !            19: #include <sys/ucomm.h>
        !            20: #include <sys/signal.h>
        !            21: #include <sys/dir.h>
        !            22: #include <sys/proc.h>
        !            23: #include <sys/user.h>
        !            24: 
        !            25: char   *symfil = "a.out";
        !            26: char   *corfil = "core";
        !            27: 
        !            28: MAP    symmap[NMAP];
        !            29: MAP    cormap[NMAP];
        !            30: 
        !            31: int fsym, fcor;
        !            32: 
        !            33: static ADDR datbase;
        !            34: ADDR txtsize, datsize, stksize;
        !            35: static ADDR entry;
        !            36: static int magic;
        !            37: 
        !            38: setsym()
        !            39: {
        !            40:        ADDR loc;
        !            41:        struct exec hdr;
        !            42:        register MAP *mp;
        !            43:        char *malloc();
        !            44: 
        !            45:        fsym = getfile(symfil, 1);
        !            46:        mp = symmap;
        !            47:        if (read(fsym, (char *)&hdr, sizeof hdr) != sizeof hdr ||
        !            48:            badmagic((int)hdr.a_magic)) {
        !            49:                mp->f = mp->b = 0;
        !            50:                mp->e = MAXFILE;
        !            51:                mp->sp = DATASP;
        !            52:                mp->flag = MPINUSE;
        !            53:                mp++;
        !            54:                mp->flag = 0;
        !            55:                hksyminit(symfil, 0);
        !            56:                return;
        !            57:        }
        !            58:        magic = hdr.a_magic;
        !            59:        entry = patoba(hdr.a_entry);
        !            60:        loc = watoba(hdr.a_text+hdr.a_data);
        !            61:        switch (magic) {
        !            62:        case A_MAGIC1:          /* only 407 files on cray! */
        !            63:                txtsize = 0;
        !            64:                datbase = 0;
        !            65:                datsize = loc;
        !            66:                mp->b = 0;
        !            67:                mp->e = loc;
        !            68:                mp->f = sizeof(hdr);
        !            69:                mp->sp = DATASP;
        !            70:                mp->flag = MPINUSE;
        !            71:                break;
        !            72:        }
        !            73:        mp++;
        !            74:        mp->flag = 0;
        !            75:        hksyminit(symfil, 1);
        !            76: }
        !            77: 
        !            78: setcor()
        !            79: {
        !            80:        register MAP *mp;
        !            81: 
        !            82:        fcor = getfile(corfil,2);
        !            83:        if (fcor < 0
        !            84:        ||  (mapimage() == 0 && mapcore() == 0)) {
        !            85:                /* not a core image */
        !            86: 
        !            87:                mp = cormap;
        !            88:                mp->b = 0;
        !            89:                mp->e = MAXFILE;
        !            90:                mp->f = 0;
        !            91:                mp->sp = DATASP;
        !            92:                mp->flag = MPINUSE;
        !            93:                mp++;
        !            94:                mp->flag = 0;
        !            95:                return;
        !            96:        }
        !            97: }
        !            98: 
        !            99: /*
        !           100:  * set up maps for a direct process image (ptrace)
        !           101:  */
        !           102: 
        !           103: #define        UOFF(x) ((int)&((struct user *)0)->x)
        !           104: 
        !           105: int
        !           106: mapimage()
        !           107: {
        !           108:        register MAP *mp;
        !           109: 
        !           110:        if (trcimage() == 0)
        !           111:                return (0);
        !           112:        txtsize = 0;    /* sigh */
        !           113:        datsize = MAXFILE;      /* sigh again */
        !           114: #if NOTDEF             /* no ID separation */
        !           115:        if (magic == IMAGIC)
        !           116:                datbase = 0;
        !           117:        else
        !           118: #endif
        !           119:                datbase = txtsize;
        !           120:        mp = cormap;
        !           121:        if (txtsize) {
        !           122:                mp->b = 0;
        !           123:                mp->e = txtsize;
        !           124:                mp->f = 0;
        !           125:                mp->flag = MPINUSE;
        !           126: #if NOTDEF             /* no ID separation */
        !           127:                if (magic == IMAGIC)
        !           128:                        mp->sp = INSTSP;
        !           129:                else
        !           130: #endif
        !           131:                        mp->sp = DATASP;
        !           132:                mp++;
        !           133:        }
        !           134:        mp->b = txtsize;
        !           135:        mp->e = mp->b + datsize;
        !           136:        mp->f = mp->b;
        !           137:        mp->sp = DATASP;
        !           138:        mp->flag = MPINUSE;
        !           139:        mp++;
        !           140:        mp->b = 0;
        !           141:        mp->e = ctob(USIZE);
        !           142:        mp->f = 0;
        !           143:        mp->sp = UBLKSP;
        !           144:        mp->flag = MPINUSE;
        !           145:        mp++;
        !           146:        mp->flag = 0;
        !           147:        rsnarf();
        !           148:        return (1);
        !           149: }
        !           150: 
        !           151: /*
        !           152:  * assume single-tasked image
        !           153:  * hack validity check: do first few entries in ascii offsets look good?
        !           154:  * better checks invited
        !           155:  */
        !           156: 
        !           157: mapcore()
        !           158: {
        !           159:        struct ucomm uc;
        !           160:        char *p;
        !           161:        struct user u;
        !           162:        register MAP *mp;
        !           163: 
        !           164:        lseek(fcor, (off_t)0, 0);
        !           165:        if (read(fcor, (char *)&uc, sizeof(uc)) != sizeof(uc))
        !           166:                return (0);
        !           167:        p = (char *)&uc.uc_ascii[0];
        !           168:        if (p[0] != 'U' && p[0] != 'u')
        !           169:                return (0);
        !           170:        p = (char *)&uc.uc_ascii[2];
        !           171:        if (p[0] != 'U' && p[0] != 'u')
        !           172:                return (0);
        !           173:        p = (char *)&uc.uc_ascii[4];    /* i tell you three times */
        !           174:        if (p[0] != 'U' && p[0] != 'u')
        !           175:                return (0);
        !           176:        lseek(fcor, (off_t)ctob(UCSIZE), 0);
        !           177:        if (read(fcor, (char *)&u, sizeof(u)) != sizeof(u))
        !           178:                return (0);
        !           179:        datsize = watoba(uc.uc_dsize);
        !           180:        mp = cormap;
        !           181:        mp->b = 0;
        !           182:        mp->e = datsize;
        !           183:        mp->f = ctob(USIZE)+ctob(UCSIZE);
        !           184:        mp->sp = DATASP;
        !           185:        mp->flag = MPINUSE;
        !           186:        mp++;
        !           187:        mp->b = 0;
        !           188:        mp->e = ctob(USIZE);
        !           189:        mp->f = ctob(UCSIZE);
        !           190:        mp->sp = UBLKSP;
        !           191:        mp->flag = MPINUSE;
        !           192:        mp++;
        !           193:        mp->flag = 0;
        !           194:        rsnarf();
        !           195:        return (1);
        !           196: }
        !           197: 
        !           198: badmagic(num)
        !           199: int num;
        !           200: {
        !           201: 
        !           202:        switch (num) {
        !           203:        case A_MAGIC1:
        !           204:                return (0);
        !           205: 
        !           206:        default:
        !           207:                return (1);
        !           208:        }
        !           209: }
        !           210: 
        !           211: cmdmap(itype, star)
        !           212: register int star, itype;
        !           213: {
        !           214:        register MAP *mp;
        !           215:        extern char lastc;
        !           216: 
        !           217:        if (itype & SYMF)
        !           218:                mp = symmap;
        !           219:        else
        !           220:                mp = cormap;
        !           221:        if (star)       /* UGH */
        !           222:                mp++;
        !           223:        if (expr(0))
        !           224:                mp->b = expv; 
        !           225:        if (expr(0))
        !           226:                mp->e = expv; 
        !           227:        if (expr(0))
        !           228:                mp->f = expv; 
        !           229:        mp->flag |= MPINUSE;
        !           230:        if (rdc()=='?' && (itype&SYMF) == 0) {
        !           231:                if (fcor)
        !           232:                        close(fcor);
        !           233:                fcor=fsym;
        !           234:                corfil=symfil;
        !           235:        } else if (lastc == '/' && itype&SYMF) {
        !           236:                if (fsym)
        !           237:                        close(fsym);
        !           238:                fsym=fcor;
        !           239:                symfil=corfil;
        !           240:        } else
        !           241:                reread();
        !           242: }
        !           243: 
        !           244: create(f)
        !           245:        char *f;
        !           246: {
        !           247:        register int fd;
        !           248: 
        !           249:        fd = creat(f, 0666);
        !           250:        if (fd < 0)
        !           251:                return (-1);
        !           252:        close(fd);
        !           253:        return (open(f, wtflag));
        !           254: }
        !           255: 
        !           256: getfile(filnam, cnt)
        !           257:        char *filnam;
        !           258: {
        !           259:        register int fsym;
        !           260: 
        !           261:        if (strcmp(filnam, "-") == 0)
        !           262:                return (-1);
        !           263:        fsym = open(filnam, wtflag);
        !           264:        if (fsym < 0 && xargc > cnt) {
        !           265:                if (wtflag)
        !           266:                        fsym = create(filnam);
        !           267:                if (fsym < 0)
        !           268:                        printf("cannot open `%s'\n", filnam);
        !           269:        }
        !           270:        return (fsym);
        !           271: }
        !           272: 
        !           273: setvar()
        !           274: {
        !           275: 
        !           276:        var[varchk('b')] = datbase;
        !           277:        var[varchk('d')] = datsize;
        !           278:        var[varchk('e')] = entry;
        !           279:        var[varchk('m')] = magic;
        !           280:        var[varchk('s')] = stksize;
        !           281:        var[varchk('t')] = txtsize;
        !           282: }

unix.superglobalmegacorp.com

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