Annotation of researchv10no/cmd/adb/g/setup.oc, revision 1.1.1.1

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

unix.superglobalmegacorp.com

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