Annotation of researchv10no/cmd/adb/68v/setup.c, 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 = "2.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:        struct exec hdr;
                     27:        register MAP *mp;
                     28:        char *malloc();
                     29: 
                     30:        fsym = getfile(symfil, 1);
                     31:        mp = symmap;
                     32:        if (read(fsym, (char *)&hdr, sizeof hdr) != sizeof hdr ||
                     33:            swal(hdr.a_magic) != A_MAGIC) {
                     34:                mp->f = mp->b = 0;
                     35:                mp->e = MAXFILE;
                     36:                mp->sp = DATASP;
                     37:                mp->flag = MPINUSE;
                     38:                mp++;
                     39:                mp->flag = 0;
                     40:                return;
                     41:        }
                     42:        magic = swal(hdr.a_magic);
                     43:        entry = swal(hdr.a_entry);
                     44:        mp->b = PGSIZE;
                     45:        txtsize = swal(hdr.a_text)+sizeof(hdr);
                     46:        mp->e = txtsize + mp->b;
                     47:        mp->f = 0;
                     48:        mp->sp = INSTSP;
                     49:        mp->flag = MPINUSE;
                     50:        mp++;
                     51:        datbase = round((WORD)swal(hdr.a_text)+sizeof(hdr), (WORD)PGSIZE) + PGSIZE;
                     52:        mp->b = datbase;
                     53:        mp->e = datsize = datbase + swal(hdr.a_data);
                     54:        mp->f = sizeof(hdr) + swal(hdr.a_text);
                     55:        mp->sp = DATASP;
                     56:        mp->flag = MPINUSE;
                     57:        mp++;
                     58:        mp->flag = 0;
                     59:        syminit(&hdr);
                     60: }
                     61: 
                     62: setcor()
                     63: {
                     64:        register MAP *mp;
                     65: 
                     66:        fcor = getfile(corfil,2);
                     67: #if NOTDEF
                     68:        if (fcor < 0
                     69:        ||  (mapimage() == 0 && mapcore() == 0)) {
                     70: #endif
                     71:                /* not a core image */
                     72: 
                     73:                mp = cormap;
                     74:                mp->b = 0;
                     75:                mp->e = MAXFILE;
                     76:                mp->f = 0;
                     77:                mp->sp = DATASP;
                     78:                mp->flag = MPINUSE;
                     79:                mp++;
                     80:                mp->flag = 0;
                     81:                return;
                     82: #if NOTDEF
                     83:        }
                     84: #endif
                     85: }
                     86: 
                     87: mapcore()
                     88: {
                     89: #if NOTDEF
                     90:        struct user u;
                     91:        register MAP *mp;
                     92: 
                     93:        lseek(fcor, (off_t)0, 0);
                     94:        if (read(fcor, (char *)&u, sizeof(u)) != sizeof(u)
                     95:        ||  badmagic(u.u_exdata.ux_mag))
                     96:                return (0);
                     97:        if (magic && magic != u.u_exdata.ux_mag)
                     98:                printf("%s: not from %s\n", corfil, symfil);
                     99:        magic = u.u_exdata.ux_mag;
                    100:        signo = u.u_arg[0];
                    101:        sigcode = u.u_code;
                    102:        txtsize = ctob(u.u_tsize);
                    103:        datsize = ctob(u.u_dsize);
                    104:        stksize = ctob(u.u_ssize);
                    105:        mp = cormap;
                    106:        switch (magic) {
                    107: 
                    108:        case OMAGIC:
                    109:                mp->b = 0;
                    110:                mp->e = txtsize + datsize;
                    111:                mp->f = ctob(UPAGES);
                    112:                mp->sp = DATASP;
                    113:                mp->flag = MPINUSE;
                    114:                mp++;
                    115:                mp->b = MAXSTOR - stksize;
                    116:                mp->e = MAXSTOR;
                    117:                mp->f = txtsize + datsize + ctob(UPAGES);
                    118:                mp->sp = DATASP;
                    119:                mp->flag = MPINUSE;
                    120:                break;
                    121: 
                    122:        case NMAGIC:
                    123:        case ZMAGIC:
                    124:                mp->b = txtsize;
                    125:                mp->e = mp->b + datsize;
                    126:                mp->f = ctob(UPAGES);
                    127:                mp->sp = DATASP;
                    128:                mp->flag = MPINUSE;
                    129:                mp++;
                    130:                mp->b = MAXSTOR - stksize;
                    131:                mp->e = MAXSTOR;
                    132:                mp->f = datsize + ctob(UPAGES);
                    133:                mp->sp = DATASP;
                    134:                mp->flag = MPINUSE;
                    135:                break;
                    136:        }
                    137:        mp++;
                    138:        mp->b = 0;
                    139:        mp->e = ctob(UPAGES);
                    140:        mp->f = 0;
                    141:        mp->sp = UBLKSP;
                    142:        mp->flag = MPINUSE;
                    143:        mp++;
                    144:        mp->flag = 0;
                    145:        rsnarf();
                    146:        return (1);
                    147: #endif
                    148: }
                    149: 
                    150: cmdmap(itype, star)
                    151: register int star, itype;
                    152: {
                    153:        register MAP *mp;
                    154:        extern char lastc;
                    155: 
                    156:        if (itype & SYMF)
                    157:                mp = symmap;
                    158:        else
                    159:                mp = cormap;
                    160:        if (star)       /* UGH */
                    161:                mp++;
                    162:        if (expr(0))
                    163:                mp->b = expv; 
                    164:        if (expr(0))
                    165:                mp->e = expv; 
                    166:        if (expr(0))
                    167:                mp->f = expv; 
                    168:        mp->flag |= MPINUSE;
                    169:        if (rdc()=='?' && (itype&SYMF) == 0) {
                    170:                if (fcor)
                    171:                        close(fcor);
                    172:                fcor=fsym;
                    173:                corfil=symfil;
                    174:        } else if (lastc == '/' && itype&SYMF) {
                    175:                if (fsym)
                    176:                        close(fsym);
                    177:                fsym=fcor;
                    178:                symfil=corfil;
                    179:        } else
                    180:                reread();
                    181: }
                    182: 
                    183: create(f)
                    184:        char *f;
                    185: {
                    186:        register int fd;
                    187: 
                    188:        fd = creat(f, 0666);
                    189:        if (fd < 0)
                    190:                return (-1);
                    191:        close(fd);
                    192:        return (open(f, wtflag));
                    193: }
                    194: 
                    195: getfile(filnam, cnt)
                    196:        char *filnam;
                    197: {
                    198:        register int fsym;
                    199: 
                    200:        if (strcmp(filnam, "-") == 0)
                    201:                return (-1);
                    202:        fsym = open(filnam, wtflag);
                    203:        if (fsym < 0 && xargc > cnt) {
                    204:                if (wtflag)
                    205:                        fsym = create(filnam);
                    206:                if (fsym < 0)
                    207:                        printf("cannot open `%s'\n", filnam);
                    208:        }
                    209:        return (fsym);
                    210: }
                    211: 
                    212: setvar()
                    213: {
                    214: 
                    215:        var[varchk('b')] = datbase;
                    216:        var[varchk('d')] = datsize;
                    217:        var[varchk('e')] = entry;
                    218:        var[varchk('m')] = magic;
                    219:        var[varchk('s')] = stksize;
                    220:        var[varchk('t')] = txtsize;
                    221: }

unix.superglobalmegacorp.com

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