Annotation of coherent/d/bin/as/i8086/asmout.c,v, revision 1.1.1.1

1.1       root        1: head     1.3;
                      2: access   ;
                      3: symbols  ;
                      4: locks    bin:1.3;
                      5: comment  @ * @;
                      6: 
                      7: 
                      8: 1.3
                      9: date     91.02.06.21.08.02;  author bin;  state Exp;
                     10: branches ;
                     11: next   1.2;
                     12: 
                     13: 1.2
                     14: date     91.02.06.20.43.59;  author bin;  state Exp;
                     15: branches ;
                     16: next   1.1;
                     17: 
                     18: 1.1
                     19: date     91.02.06.20.43.51;  author bin;  state Exp;
                     20: branches ;
                     21: next   ;
                     22: 
                     23: 
                     24: desc
                     25: @steve 2/6/91
                     26: Initial MWC RCS revision.
                     27: @
                     28: 
                     29: 
                     30: 1.3
                     31: log
                     32: @steve 2/6/91
                     33: Changed bogus condition in if command (lines 239ff.)
                     34: so that the -x flag strips local symbols from object as advertised.
                     35: @
                     36: text
                     37: @/*
                     38:  * Output routines.
                     39:  * Intel iAPX-86.
                     40:  * Small model.
                     41:  */
                     42: #include <canon.h>
                     43: #include "asm.h"
                     44: 
                     45: #define NTXT   128
                     46: #define NREL   128
                     47: 
                     48: #define outlst(b)      { if (cp < &cb[NCODE]) *cp++ = (b); }
                     49: 
                     50: address        txtla;
                     51: long   crbase;
                     52: long   crseek;
                     53: struct ldheader ldh;
                     54: struct loc *txtlp;
                     55: char   txt[NTXT];
                     56: char   rel[NREL];
                     57: char   *txtp   = { txt };
                     58: char   *relp   = { rel };
                     59: 
                     60: outab(b)
                     61: {
                     62:        if (pass == 2) {
                     63:                if (inbss)
                     64:                        serr();
                     65:                else {
                     66:                        outlst(b);
                     67:                        outchk(1, 0);
                     68:                        *txtp++ = fbyte(b);
                     69:                }
                     70:        }
                     71:        ++dot->s_addr;
                     72: }
                     73: 
                     74: outaw(w)
                     75: {
                     76:        if (pass == 2) {
                     77:                if (inbss)
                     78:                        serr();
                     79:                else {
                     80:                        outlst(fbyte(w));
                     81:                        outlst(sbyte(w));
                     82:                        outchk(2, 0);
                     83:                        *txtp++ = fbyte(w);
                     84:                        *txtp++ = sbyte(w);
                     85:                }
                     86:        }
                     87:        dot->s_addr += 2;
                     88: }
                     89: 
                     90: outrb(esp, pcrf)
                     91: register struct expr *esp;
                     92: {
                     93:        register address a;
                     94:        register n;
                     95:        int t;
                     96: 
                     97:        if (pass == 2) {
                     98:                if (inbss)
                     99:                        serr();
                    100:                else {
                    101:                        t = esp->e_type;
                    102:                        if (t==E_AREG || t==E_ASEG)
                    103:                                t = E_ACON;
                    104:                        a = esp->e_addr;
                    105:                        if (pcrf)
                    106:                                a -= dot->s_addr+1;
                    107:                        outlst(fbyte(a));
                    108:                        if (t == E_ACON) {
                    109:                                n = 0;
                    110:                                if (pcrf)
                    111:                                        n = 3;
                    112:                                outchk(1, n);
                    113:                                *txtp++ = fbyte(a);
                    114:                                if (pcrf) {
                    115:                                        *relp++ = LR_BYTE|LR_PCR|L_ABS;
                    116:                                        *relp++ = fbyte(dot->s_addr);
                    117:                                        *relp++ = sbyte(dot->s_addr);
                    118:                                }
                    119:                        } else {
                    120:                                n = 3;
                    121:                                if (t == E_SYM)
                    122:                                        n = 5;
                    123:                                outchk(1, n);
                    124:                                *txtp++ = fbyte(a);
                    125:                                n = LR_BYTE;
                    126:                                if (pcrf)
                    127:                                        n |= LR_PCR;
                    128:                                if (t == E_SYM)
                    129:                                        n |= L_SYM;
                    130:                                else
                    131:                                        n |= esp->e_base.e_lp->l_seg;
                    132:                                *relp++ = n;
                    133:                                *relp++ = fbyte(dot->s_addr);
                    134:                                *relp++ = sbyte(dot->s_addr);
                    135:                                if (t == E_SYM) {
                    136:                                        n = esp->e_base.e_sp->s_ref;
                    137:                                        *relp++ = fbyte(n);
                    138:                                        *relp++ = sbyte(n);
                    139:                                }
                    140:                        }
                    141:                }
                    142:        }
                    143:        ++dot->s_addr;
                    144: }
                    145: 
                    146: outrw(esp, pcrf)
                    147: register struct expr *esp;
                    148: {
                    149:        register address a;
                    150:        register n;
                    151:        int t;
                    152: 
                    153:        if (pass == 2) {
                    154:                if (inbss)
                    155:                        serr();
                    156:                else {
                    157:                        t = esp->e_type;
                    158:                        if (t==E_AREG || t==E_ASEG)
                    159:                                t = E_ACON;
                    160:                        a = esp->e_addr;
                    161:                        if (pcrf)
                    162:                                a -= dot->s_addr+2;
                    163:                        outlst(fbyte(a));
                    164:                        outlst(sbyte(a));
                    165:                        if (t == E_ACON) {
                    166:                                n = 0;
                    167:                                if (pcrf)
                    168:                                        n = 3;
                    169:                                outchk(2, n);
                    170:                                *txtp++ = fbyte(a);
                    171:                                *txtp++ = sbyte(a);
                    172:                                if (pcrf) {
                    173:                                        *relp++ = LR_WORD|LR_PCR|L_ABS;
                    174:                                        *relp++ = fbyte(dot->s_addr);
                    175:                                        *relp++ = sbyte(dot->s_addr);
                    176:                                }
                    177:                        } else {
                    178:                                n = 3;
                    179:                                if (t == E_SYM)
                    180:                                        n = 5;
                    181:                                outchk(2, n);
                    182:                                *txtp++ = fbyte(a);
                    183:                                *txtp++ = sbyte(a);
                    184:                                n = LR_WORD;
                    185:                                if (pcrf)
                    186:                                        n |= LR_PCR;
                    187:                                if (t == E_SYM)
                    188:                                        n |= L_SYM;
                    189:                                else
                    190:                                        n |= esp->e_base.e_lp->l_seg;
                    191:                                *relp++ = n;
                    192:                                *relp++ = fbyte(dot->s_addr);
                    193:                                *relp++ = sbyte(dot->s_addr);
                    194:                                if (t == E_SYM) {
                    195:                                        n = esp->e_base.e_sp->s_ref;
                    196:                                        *relp++ = fbyte(n);
                    197:                                        *relp++ = sbyte(n);
                    198:                                }
                    199:                        }
                    200:                }
                    201:        }
                    202:        dot->s_addr += 2;
                    203: }
                    204: 
                    205: /*
                    206:  * Make sure there is room in
                    207:  * the buffers for `nt' bytes worth
                    208:  * text and `nr' bytes of rel.
                    209:  * If not, write the buffers out
                    210:  * to the file.
                    211:  */
                    212: outchk(nt, nr)
                    213: {
                    214:        register unsigned n;
                    215:        register tn;
                    216:        long ts;
                    217: 
                    218:        if (txtp+nt>&txt[NTXT] || relp+nr>&rel[NREL]) {
                    219:                if ((n = txtp-txt) != 0) {
                    220:                        ts = txtla + sizeof(ldh);
                    221:                        tn = txtlp->l_seg;
                    222:                        if (tn > L_BSSI) {
                    223:                                ts -= ldh.l_ssize[L_BSSI];
                    224:                                if (tn > L_BSSD)
                    225:                                        ts -= ldh.l_ssize[L_BSSD];
                    226:                        }
                    227:                        fseek(ofp, ts, 0);
                    228:                        xwrite(txt, sizeof(char), n);
                    229:                        if ((n = relp-rel) != 0) {
                    230:                                fseek(ofp, crseek, 0);
                    231:                                xwrite(rel, sizeof(char), n);
                    232:                                crseek += n;
                    233:                                relp = rel;
                    234:                        }
                    235:                }
                    236:                txtp = txt;
                    237:        }
                    238:        if (txtp == txt) {
                    239:                txtla = dot->s_addr;
                    240:                txtlp = dot->s_base.s_lp;
                    241:        }
                    242: }
                    243: 
                    244: outinit()
                    245: {
                    246:        register struct loc *lp;
                    247:        register struct sym *sp;
                    248:        register i;
                    249:        struct ldsym lds;
                    250:        int rn;
                    251:        long sb, ss;
                    252: 
                    253:        ldh.l_magic = L_MAGIC;
                    254:        ldh.l_flag = 0;
                    255:        ldh.l_machine = M_8086;
                    256:        ldh.l_entry = 0;
                    257:        sb = sizeof(ldh);
                    258:        for (i=0; i<nloc; ++i) {
                    259:                ss = 0;
                    260:                lp = loc[i];
                    261:                while (lp != NULL) {
                    262:                        ss += locrup(lp->l_break);
                    263:                        lp = lp->l_lp;
                    264:                }
                    265:                ldh.l_ssize[i] = ss;
                    266:                if (i!=L_BSSI && i!=L_BSSD)
                    267:                        sb += ss;
                    268:        }
                    269:        fseek(ofp, sb, 0);
                    270:        ss = 0;
                    271:        rn = 0;
                    272:        for (i=0; i<NHASH; ++i) {
                    273:                sp = symhash[i];
                    274:                while (sp != NULL) {
                    275:                        if (((sp->s_flag&S_SYMT) != 0)
                    276:                        &&  ((xflag == 0) || ((sp->s_flag&S_GBL) != 0))) {
                    277:                                sp->s_ref = rn++;
                    278:                                symcopy(lds.ls_id, sp->s_id);
                    279:                                if (sp->s_kind == S_NEW)
                    280:                                        lds.ls_type = L_REF;
                    281:                                else if (sp->s_type != E_DIR)
                    282:                                        lds.ls_type = L_ABS;
                    283:                                else
                    284:                                        lds.ls_type = sp->s_base.s_lp->l_seg;
                    285:                                if ((sp->s_flag&S_GBL) != 0)
                    286:                                        lds.ls_type |= L_GLOBAL;
                    287:                                lds.ls_addr = sp->s_addr;
                    288:                                xwrite(&lds, sizeof(lds), 1);
                    289:                                ss += sizeof(lds);
                    290:                        }
                    291:                        sp = sp->s_sp;
                    292:                }
                    293:        }
                    294:        ldh.l_ssize[L_SYM] = ss;
                    295:        crseek = sb+ss;
                    296:        crbase = crseek;
                    297: }
                    298: 
                    299: /*
                    300:  * Finish up l.out
                    301:  */
                    302: outfinish()
                    303: {
                    304:        register int i;
                    305: 
                    306:        ldh.l_ssize[L_REL] = crseek-crbase;
                    307:        canint(ldh.l_magic);
                    308:        canint(ldh.l_flag);
                    309:        canint(ldh.l_machine);
                    310:        canvaddr(ldh.l_entry);
                    311:        for (i=0; i<NLSEG; i++)
                    312:                cansize(ldh.l_ssize[i]);
                    313:        fseek(ofp, (long)0, 0);
                    314:        xwrite(&ldh, sizeof(ldh), 1);
                    315:        fclose(ofp);
                    316: }
                    317: 
                    318: /*
                    319:  * Write code file.
                    320:  * Check for any errors.
                    321:  */
                    322: xwrite(p, s, n)
                    323: char *p;
                    324: {
                    325:        if (fwrite(p, s, n, ofp) != n) {
                    326:                fprintf(stderr, "%s: I/O error.\n", ofn);
                    327:                exit(1);
                    328:        }
                    329: }
                    330: @
                    331: 
                    332: 
                    333: 1.2
                    334: log
                    335: @steve 2/6/91
                    336: Descriptive error messages.
                    337: @
                    338: text
                    339: @d239 2
                    340: a240 4
                    341:                        if ((sp->s_flag&S_SYMT) != 0
                    342:                        && (xflag == 0
                    343:                        || (sp->s_flag&S_GBL) != 0
                    344:                        ||  sp->s_id[0] != 'L')) {
                    345: @
                    346: 
                    347: 
                    348: 1.1
                    349: log
                    350: @Initial revision
                    351: @
                    352: text
                    353: @d28 1
                    354: a28 1
                    355:                        err('s');
                    356: d42 1
                    357: a42 1
                    358:                        err('s');
                    359: d63 1
                    360: a63 1
                    361:                        err('s');
                    362: d119 1
                    363: a119 1
                    364:                        err('s');
                    365: @

unix.superglobalmegacorp.com

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