Annotation of researchv10no/cmd/adb/11v/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 vax dependent
                      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 = "11a.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((int)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;
                     53:                mp->e = loc;
                     54:                mp->f = sizeof(hdr);
                     55:                mp->sp = DATASP;
                     56:                mp->flag = MPINUSE;
                     57:                break;
                     58: 
                     59:        case A_MAGIC2:
                     60:                mp->b = 0;
                     61:                mp->e = txtsize = hdr.a_text;
                     62:                mp->f = sizeof(hdr);
                     63:                mp->sp = INSTSP;
                     64:                mp->flag = MPINUSE;
                     65:                mp++;
                     66:                mp->b = datbase = round((WORD)hdr.a_text, (WORD)RRND);
                     67:                mp->e = datsize = datbase + hdr.a_data;
                     68:                mp->f = sizeof(hdr) + hdr.a_text;
                     69:                mp->sp = DATASP;
                     70:                mp->flag = MPINUSE;
                     71:                break;
                     72: 
                     73:        case A_MAGIC3:
                     74:                mp->b = 0;
                     75:                mp->e = txtsize = hdr.a_text;
                     76:                mp->f = sizeof(hdr);
                     77:                mp->sp = INSTSP;
                     78:                mp->flag = MPINUSE;
                     79:                mp++;
                     80:                mp->b = datbase = 0;
                     81:                mp->e = datsize = datbase + hdr.a_data;
                     82:                mp->f = sizeof(hdr) + hdr.a_text;
                     83:                mp->sp = DATASP;
                     84:                mp->flag = MPINUSE;
                     85:                break;
                     86:        }
                     87:        mp++;
                     88:        mp->flag = 0;
                     89:        syminit(&hdr);
                     90: }
                     91: 
                     92: setcor()
                     93: {
                     94:        register MAP *mp;
                     95: 
                     96:        fcor = getfile(corfil,2);
                     97: #if NOTDEF
                     98:        if (fcor < 0
                     99:        ||  (mapimage() == 0 && mapcore() == 0)) {
                    100: #endif
                    101:                /* not a core image */
                    102: 
                    103:                mp = cormap;
                    104:                mp->b = 0;
                    105:                mp->e = MAXFILE;
                    106:                mp->f = 0;
                    107:                mp->sp = DATASP;
                    108:                mp->flag = MPINUSE;
                    109:                mp++;
                    110:                mp->flag = 0;
                    111:                return;
                    112: #if NOTDEF
                    113:        }
                    114: #endif
                    115: }
                    116: 
                    117: mapcore()
                    118: {
                    119: #if NOTDEF
                    120:        struct user u;
                    121:        register MAP *mp;
                    122: 
                    123:        lseek(fcor, (off_t)0, 0);
                    124:        if (read(fcor, (char *)&u, sizeof(u)) != sizeof(u)
                    125:        ||  badmagic(u.u_exdata.ux_mag))
                    126:                return (0);
                    127:        if (magic && magic != u.u_exdata.ux_mag)
                    128:                printf("%s: not from %s\n", corfil, symfil);
                    129:        magic = u.u_exdata.ux_mag;
                    130:        signo = u.u_arg[0];
                    131:        sigcode = u.u_code;
                    132:        txtsize = ctob(u.u_tsize);
                    133:        datsize = ctob(u.u_dsize);
                    134:        stksize = ctob(u.u_ssize);
                    135:        mp = cormap;
                    136:        switch (magic) {
                    137: 
                    138:        case OMAGIC:
                    139:                mp->b = 0;
                    140:                mp->e = txtsize + datsize;
                    141:                mp->f = ctob(UPAGES);
                    142:                mp->sp = DATASP;
                    143:                mp->flag = MPINUSE;
                    144:                mp++;
                    145:                mp->b = MAXSTOR - stksize;
                    146:                mp->e = MAXSTOR;
                    147:                mp->f = txtsize + datsize + ctob(UPAGES);
                    148:                mp->sp = DATASP;
                    149:                mp->flag = MPINUSE;
                    150:                break;
                    151: 
                    152:        case NMAGIC:
                    153:        case ZMAGIC:
                    154:                mp->b = txtsize;
                    155:                mp->e = mp->b + datsize;
                    156:                mp->f = ctob(UPAGES);
                    157:                mp->sp = DATASP;
                    158:                mp->flag = MPINUSE;
                    159:                mp++;
                    160:                mp->b = MAXSTOR - stksize;
                    161:                mp->e = MAXSTOR;
                    162:                mp->f = datsize + ctob(UPAGES);
                    163:                mp->sp = DATASP;
                    164:                mp->flag = MPINUSE;
                    165:                break;
                    166:        }
                    167:        mp++;
                    168:        mp->b = 0;
                    169:        mp->e = ctob(UPAGES);
                    170:        mp->f = 0;
                    171:        mp->sp = UBLKSP;
                    172:        mp->flag = MPINUSE;
                    173:        mp++;
                    174:        mp->flag = 0;
                    175:        rsnarf();
                    176:        return (1);
                    177: #endif
                    178: }
                    179: 
                    180: badmagic(num)
                    181: int num;
                    182: {
                    183: 
                    184:        switch (num) {
                    185:        case A_MAGIC1:
                    186:        case A_MAGIC2:
                    187:        case A_MAGIC3:
                    188:                return (0);
                    189: 
                    190:        default:
                    191:                return (1);
                    192:        }
                    193: }
                    194: 
                    195: cmdmap(itype, star)
                    196: register int star, itype;
                    197: {
                    198:        register MAP *mp;
                    199:        extern char lastc;
                    200: 
                    201:        if (itype & SYMF)
                    202:                mp = symmap;
                    203:        else
                    204:                mp = cormap;
                    205:        if (star)       /* UGH */
                    206:                mp++;
                    207:        if (expr(0))
                    208:                mp->b = expv; 
                    209:        if (expr(0))
                    210:                mp->e = expv; 
                    211:        if (expr(0))
                    212:                mp->f = expv; 
                    213:        mp->flag |= MPINUSE;
                    214:        if (rdc()=='?' && (itype&SYMF) == 0) {
                    215:                if (fcor)
                    216:                        close(fcor);
                    217:                fcor=fsym;
                    218:                corfil=symfil;
                    219:        } else if (lastc == '/' && itype&SYMF) {
                    220:                if (fsym)
                    221:                        close(fsym);
                    222:                fsym=fcor;
                    223:                symfil=corfil;
                    224:        } else
                    225:                reread();
                    226: }
                    227: 
                    228: create(f)
                    229:        char *f;
                    230: {
                    231:        register int fd;
                    232: 
                    233:        fd = creat(f, 0666);
                    234:        if (fd < 0)
                    235:                return (-1);
                    236:        close(fd);
                    237:        return (open(f, wtflag));
                    238: }
                    239: 
                    240: getfile(filnam, cnt)
                    241:        char *filnam;
                    242: {
                    243:        register int fsym;
                    244: 
                    245:        if (strcmp(filnam, "-") == 0)
                    246:                return (-1);
                    247:        fsym = open(filnam, wtflag);
                    248:        if (fsym < 0 && xargc > cnt) {
                    249:                if (wtflag)
                    250:                        fsym = create(filnam);
                    251:                if (fsym < 0)
                    252:                        printf("cannot open `%s'\n", filnam);
                    253:        }
                    254:        return (fsym);
                    255: }
                    256: 
                    257: setvar()
                    258: {
                    259: 
                    260:        var[varchk('b')] = datbase;
                    261:        var[varchk('d')] = datsize;
                    262:        var[varchk('e')] = entry;
                    263:        var[varchk('m')] = magic;
                    264:        var[varchk('s')] = stksize;
                    265:        var[varchk('t')] = txtsize;
                    266: }

unix.superglobalmegacorp.com

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