Annotation of researchv10no/cmd/adb/seq/setup.c, revision 1.1.1.1

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

unix.superglobalmegacorp.com

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