|
|
1.1 ! root 1: #include "defs" ! 2: ! 3: #ifdef SDB ! 4: # include <a.out.h> ! 5: extern int types2[]; ! 6: # ifndef N_SO ! 7: # include <stab.h> ! 8: # endif ! 9: #endif ! 10: ! 11: #include "pccdefs" ! 12: ! 13: /* ! 14: VAX-11/780 - SPECIFIC ROUTINES ! 15: */ ! 16: ! 17: ! 18: int maxregvar = MAXREGVAR; ! 19: int regnum[] = { 11, 10, 9, 8, 7, 6 } ; ! 20: static int regmask[] = { 0, 0x800, 0xc00, 0xe00, 0xf00, 0xf80, 0xfc0 }; ! 21: ! 22: ! 23: ! 24: ftnint intcon[14] = ! 25: { 2, 2, 2, 2, ! 26: 15, 31, 24, 56, ! 27: -128, -128, 127, 127, ! 28: 32767, 2147483647 }; ! 29: ! 30: #if HERE == VAX ! 31: /* then put in constants in octal */ ! 32: long realcon[6][2] = ! 33: { ! 34: { 0200, 0 }, ! 35: { 0200, 0 }, ! 36: { 037777677777, 0 }, ! 37: { 037777677777, 037777777777 }, ! 38: { 032200, 0 }, ! 39: { 022200, 0 } ! 40: }; ! 41: #else ! 42: double realcon[6] = ! 43: { ! 44: 2.9387358771e-39, ! 45: 2.938735877055718800e-39 ! 46: 1.7014117332e+38, ! 47: 1.701411834604692250e+38 ! 48: 5.960464e-8, ! 49: 1.38777878078144567e-17, ! 50: }; ! 51: #endif ! 52: ! 53: ! 54: ! 55: ! 56: prsave(proflab) ! 57: int proflab; ! 58: { ! 59: if(profileflag) ! 60: { ! 61: fprintf(asmfile, "L%d:\t.space\t4\n", proflab); ! 62: p2pi("\tmovab\tL%d,r0", proflab); ! 63: p2pass("\tjsb\tmcount"); ! 64: } ! 65: p2pi("\tsubl2\t$LF%d,sp", procno); ! 66: } ! 67: ! 68: ! 69: ! 70: goret(type) ! 71: int type; ! 72: { ! 73: p2pass("\tret"); ! 74: } ! 75: ! 76: ! 77: ! 78: ! 79: /* ! 80: * move argument slot arg1 (relative to ap) ! 81: * to slot arg2 (relative to ARGREG) ! 82: */ ! 83: ! 84: mvarg(type, arg1, arg2) ! 85: int type, arg1, arg2; ! 86: { ! 87: p2pij("\tmovl\t%d(ap),%d(fp)", arg1+ARGOFFSET, arg2+argloc); ! 88: } ! 89: ! 90: ! 91: ! 92: ! 93: prlabel(fp, k) ! 94: FILEP fp; ! 95: int k; ! 96: { ! 97: fprintf(fp, "L%d:\n", k); ! 98: } ! 99: ! 100: ! 101: ! 102: prconi(fp, type, n) ! 103: FILEP fp; ! 104: int type; ! 105: ftnint n; ! 106: { ! 107: fprintf(fp, "\t%s\t%ld\n", (type==TYSHORT ? ".word" : ".long"), n); ! 108: } ! 109: ! 110: ! 111: ! 112: prcona(fp, a) ! 113: FILEP fp; ! 114: ftnint a; ! 115: { ! 116: fprintf(fp, "\t.long\tL%ld\n", a); ! 117: } ! 118: ! 119: ! 120: ! 121: #ifndef vax ! 122: prconr(fp, type, x) ! 123: FILEP fp; ! 124: int type; ! 125: float x; ! 126: { ! 127: fprintf(fp, "\t%s\t0f%e\n", (type==TYREAL ? ".float" : ".double"), x); ! 128: } ! 129: #endif ! 130: ! 131: #ifdef vax ! 132: prconr(fp, type, x) ! 133: FILEP fp; ! 134: int type; ! 135: double x; ! 136: { ! 137: /* non-portable cheat to preserve bit patterns */ ! 138: union { double xd; long int xl[2]; } cheat; ! 139: cheat.xd = x; ! 140: if(type == TYREAL) ! 141: {float y = x; fprintf(fp, "\t.long\t0x%X\n", *(long *) &y); } ! 142: else ! 143: fprintf(fp, "\t.long\t0x%X,0x%X\n", cheat.xl[0], cheat.xl[1]); ! 144: } ! 145: #endif ! 146: ! 147: ! 148: ! 149: praddr(fp, stg, varno, offset) ! 150: FILE *fp; ! 151: int stg, varno; ! 152: ftnint offset; ! 153: { ! 154: char *memname(); ! 155: ! 156: if(stg == STGNULL) ! 157: fprintf(fp, "\t.long\t0\n"); ! 158: else ! 159: { ! 160: fprintf(fp, "\t.long\t%s", memname(stg,varno)); ! 161: if(offset) ! 162: fprintf(fp, "+%ld", offset); ! 163: fprintf(fp, "\n"); ! 164: } ! 165: } ! 166: ! 167: ! 168: ! 169: ! 170: preven(k) ! 171: int k; ! 172: { ! 173: register int lg; ! 174: ! 175: if(k > 4) ! 176: lg = 3; ! 177: else if(k > 2) ! 178: lg = 2; ! 179: else if(k > 1) ! 180: lg = 1; ! 181: else ! 182: return; ! 183: fprintf(asmfile, "\t.align\t%d\n", lg); ! 184: } ! 185: ! 186: ! 187: ! 188: vaxgoto(index, nlab, labs) ! 189: expptr index; ! 190: register int nlab; ! 191: struct Labelblock *labs[]; ! 192: { ! 193: register int i; ! 194: register int arrlab; ! 195: ! 196: putforce(TYINT, index); ! 197: p2pi("\tcasel\tr0,$1,$%d", nlab-1); ! 198: p2pi("L%d:", arrlab = newlabel() ); ! 199: for(i = 0; i< nlab ; ++i) ! 200: if( labs[i] ) ! 201: p2pij("\t.word\tL%d-L%d", labs[i]->labelno, arrlab); ! 202: } ! 203: ! 204: ! 205: prarif(p, neg, zer, pos) ! 206: expptr p; ! 207: int neg, zer, pos; ! 208: { ! 209: putforce(p->headblock.vtype, p); ! 210: if( ISINT(p->headblock.vtype) ) ! 211: p2pass("\ttstl\tr0"); ! 212: else ! 213: p2pass("\ttstd\tr0"); ! 214: p2pi("\tjlss\tL%d", neg); ! 215: p2pi("\tjeql\tL%d", zer); ! 216: p2pi("\tjbr\tL%d", pos); ! 217: } ! 218: ! 219: ! 220: ! 221: ! 222: char *memname(stg, mem) ! 223: int stg, mem; ! 224: { ! 225: static char s[20]; ! 226: ! 227: switch(stg) ! 228: { ! 229: case STGCOMMON: ! 230: case STGEXT: ! 231: sprintf(s, "_%s", varstr(XL, extsymtab[mem].extname) ); ! 232: break; ! 233: ! 234: case STGBSS: ! 235: case STGINIT: ! 236: sprintf(s, "v.%d", mem); ! 237: break; ! 238: ! 239: case STGCONST: ! 240: sprintf(s, "L%d", mem); ! 241: break; ! 242: ! 243: case STGEQUIV: ! 244: sprintf(s, "q.%d", mem+eqvstart); ! 245: break; ! 246: ! 247: default: ! 248: badstg("memname", stg); ! 249: } ! 250: return(s); ! 251: } ! 252: ! 253: /* ! 254: * this shouldn't be here (or memname shouldn't) ! 255: * but i'm too lazy to fix it ! 256: */ ! 257: ! 258: char * ! 259: ftnname(stg, name) ! 260: char *name; ! 261: { ! 262: static char s[40]; ! 263: ! 264: switch (stg) { ! 265: case STGCOMMON: ! 266: case STGEXT: ! 267: sprintf(s, "_%s", varstr(XL, name) ); ! 268: break; ! 269: default: ! 270: badstg("ftnname", stg); ! 271: } ! 272: return (s); ! 273: } ! 274: ! 275: ! 276: ! 277: ! 278: prlocvar(s, len) ! 279: char *s; ! 280: ftnint len; ! 281: { ! 282: fprintf(asmfile, "\t.lcomm\t%s,%ld\n", s, len); ! 283: } ! 284: ! 285: ! 286: ! 287: prext(name, leng, init) ! 288: char *name; ! 289: ftnint leng; ! 290: int init; ! 291: { ! 292: if(leng == 0) ! 293: fprintf(asmfile, "\t.globl\t_%s\n", name); ! 294: else ! 295: fprintf(asmfile, "\t.comm\t_%s,%ld\n", name, leng); ! 296: } ! 297: ! 298: ! 299: ! 300: ! 301: ! 302: prendproc() ! 303: { ! 304: } ! 305: ! 306: ! 307: ! 308: ! 309: prtail() ! 310: { ! 311: } ! 312: ! 313: ! 314: ! 315: ! 316: ! 317: prolog(ep, argvec) ! 318: struct Entrypoint *ep; ! 319: Addrp argvec; ! 320: { ! 321: int i, argslot, proflab; ! 322: int size; ! 323: register chainp p; ! 324: register Namep q; ! 325: register struct Dimblock *dp; ! 326: expptr tp; ! 327: ! 328: p2pass("\t.align\t1"); ! 329: ! 330: ! 331: if(procclass == CLMAIN) { ! 332: if(fudgelabel) ! 333: { ! 334: if(ep->entryname) { ! 335: p2ps("_%s:", varstr(XL, ep->entryname->extname)); ! 336: p2pi("\t.word\tLWM%d", procno); ! 337: } ! 338: putlabel(fudgelabel); ! 339: fudgelabel = 0; ! 340: fixlwm(); ! 341: } ! 342: else ! 343: { ! 344: p2pass( "_MAIN__:" ); ! 345: if(ep->entryname == NULL) ! 346: p2pi("\t.word\tLWM%d", procno); ! 347: } ! 348: ! 349: } else if(ep->entryname) ! 350: if(fudgelabel) ! 351: { ! 352: putlabel(fudgelabel); ! 353: fudgelabel = 0; ! 354: fixlwm(); ! 355: } ! 356: else ! 357: { ! 358: p2ps("_%s:", varstr(XL, ep->entryname->extname)); ! 359: p2pi("\t.word\tLWM%d", procno); ! 360: prsave(newlabel()); ! 361: } ! 362: ! 363: if(procclass == CLBLOCK) ! 364: return; ! 365: if(argvec) ! 366: { ! 367: argloc = argvec->memoffset->constblock.const.ci + SZINT; ! 368: /* first slot holds count */ ! 369: if(proctype == TYCHAR) ! 370: { ! 371: mvarg(TYADDR, 0, chslot); ! 372: mvarg(TYLENG, SZADDR, chlgslot); ! 373: argslot = SZADDR + SZLENG; ! 374: } ! 375: else if( ISCOMPLEX(proctype) ) ! 376: { ! 377: mvarg(TYADDR, 0, cxslot); ! 378: argslot = SZADDR; ! 379: } ! 380: else ! 381: argslot = 0; ! 382: ! 383: for(p = ep->arglist ; p ; p =p->nextp) ! 384: { ! 385: q = (Namep) (p->datap); ! 386: mvarg(TYADDR, argslot, q->vardesc.varno); ! 387: argslot += SZADDR; ! 388: } ! 389: for(p = ep->arglist ; p ; p = p->nextp) ! 390: { ! 391: q = (Namep) (p->datap); ! 392: if(q->vtype==TYCHAR && q->vclass!=CLPROC) ! 393: { ! 394: if(q->vleng && ! ISCONST(q->vleng) ) ! 395: mvarg(TYLENG, argslot, ! 396: q->vleng->addrblock.memno); ! 397: argslot += SZLENG; ! 398: } ! 399: } ! 400: p2pi("\taddl3\t$%d,fp,ap", argloc-ARGOFFSET); ! 401: p2pi("\tmovl\t$%d,(ap)\n", lastargslot/SZADDR); ! 402: } ! 403: ! 404: for(p = ep->arglist ; p ; p = p->nextp) ! 405: { ! 406: q = (Namep) (p->datap); ! 407: if(dp = q->vdim) ! 408: { ! 409: for(i = 0 ; i < dp->ndim ; ++i) ! 410: if(dp->dims[i].dimexpr) ! 411: puteq( fixtype(cpexpr(dp->dims[i].dimsize)), ! 412: fixtype(cpexpr(dp->dims[i].dimexpr))); ! 413: size = typesize[ q->vtype ]; ! 414: if(q->vtype == TYCHAR) ! 415: if( ISICON(q->vleng) ) ! 416: size *= q->vleng->constblock.const.ci; ! 417: else ! 418: size = -1; ! 419: ! 420: /* on VAX, get more efficient subscripting if subscripts ! 421: have zero-base, so fudge the argument pointers for arrays. ! 422: Not done if array bounds are being checked. ! 423: */ ! 424: if(dp->basexpr) ! 425: puteq( cpexpr(fixtype(dp->baseoffset)), ! 426: cpexpr(fixtype(dp->basexpr))); ! 427: ! 428: if(! checksubs) ! 429: { ! 430: if(dp->basexpr) ! 431: { ! 432: if(size > 0) ! 433: tp = (expptr) ICON(size); ! 434: else ! 435: tp = (expptr) cpexpr(q->vleng); ! 436: putforce(TYINT, ! 437: fixtype( mkexpr(OPSTAR, tp, ! 438: cpexpr(dp->baseoffset)) )); ! 439: p2pi("\tsubl2\tr0,%d(ap)", ! 440: p->datap->nameblock.vardesc.varno + ! 441: ARGOFFSET); ! 442: } ! 443: else if(dp->baseoffset->constblock.const.ci != 0) ! 444: { ! 445: char buff[25]; ! 446: if(size > 0) ! 447: { ! 448: sprintf(buff, "\tsubl2\t$%ld,%d(ap)", ! 449: dp->baseoffset->constblock.const.ci * size, ! 450: p->datap->nameblock.vardesc.varno + ! 451: ARGOFFSET); ! 452: } ! 453: else { ! 454: putforce(TYINT, mkexpr(OPSTAR, cpexpr(dp->baseoffset), ! 455: cpexpr(q->vleng) )); ! 456: sprintf(buff, "\tsubl2\tr0,%d(ap)", ! 457: p->datap->nameblock.vardesc.varno + ! 458: ARGOFFSET); ! 459: } ! 460: p2pass(buff); ! 461: } ! 462: } ! 463: } ! 464: } ! 465: ! 466: if(typeaddr) ! 467: puteq( cpexpr(typeaddr), mkaddcon(ep->typelabel) ); ! 468: /* replace to avoid long jump problem ! 469: putgoto(ep->entrylabel); ! 470: */ ! 471: p2pi("\tjmp\tL%d", ep->entrylabel); ! 472: } ! 473: ! 474: fixlwm() ! 475: { ! 476: extern lwmno; ! 477: if (lwmno == procno) ! 478: return; ! 479: fprintf(asmfile, "\t.set\tLWM%d,0x%x\n", ! 480: procno, regmask[highregvar]); ! 481: lwmno = procno; ! 482: } ! 483: ! 484: ! 485: prhead(fp) ! 486: FILEP fp; ! 487: { ! 488: #if FAMILY==PCC ! 489: p2triple(P2LBRACKET, ARGREG-highregvar, procno); ! 490: p2word( (long) (BITSPERCHAR*autoleng) ); ! 491: p2flush(); ! 492: #endif ! 493: } ! 494: ! 495: ! 496: ! 497: prdbginfo() ! 498: { ! 499: } ! 500: ! 501: #ifdef SDB ! 502: ! 503: ! 504: # ifdef UCBVAXASM ! 505: char *stabdline(code, type) ! 506: int code; ! 507: int type; ! 508: { ! 509: static char buff[30]; ! 510: ! 511: sprintf(buff, "\t.stabd\t0%o,0,0%o", code, type); ! 512: return(buff); ! 513: } ! 514: # endif ! 515: ! 516: ! 517: prstab(s, code, type, loc) ! 518: char *s, *loc; ! 519: int code, type; ! 520: { ! 521: char * stabline(); ! 522: ! 523: if(sdbflag) ! 524: p2pass( stabline(s,code,type,loc) ); ! 525: } ! 526: ! 527: ! 528: ! 529: char *stabline(s, code, type, loc) ! 530: register char *s; ! 531: int code; ! 532: int type; ! 533: char *loc; ! 534: { ! 535: static char buff[512] = "\t.stab\t\t"; ! 536: register char *t; ! 537: register int i = 0; ! 538: ! 539: #ifdef UCBVAXASM ! 540: t = buff + 8; ! 541: if(s == NULL) ! 542: buff[6] = 'n'; /* .stabn line */ ! 543: else ! 544: { ! 545: buff[6] = 's'; /* .stabs line */ ! 546: *t++ = '"'; ! 547: while(*s!='\0' && *s!=' ') ! 548: { ! 549: #ifndef UCBPASS2 ! 550: if (i == 8) ! 551: break; ! 552: #endif ! 553: *t++ = *s++; ! 554: ++i; ! 555: } ! 556: *t++ = '"'; ! 557: *t++ = ','; ! 558: } ! 559: ! 560: #else ! 561: t = buff + 7; ! 562: if(s) ! 563: while( *s!='\0' && *s!=' ' && i<8 ) ! 564: { ! 565: *t++ = '\''; ! 566: *t++ = *s++; ! 567: *t++ = ','; ! 568: ++i; ! 569: } ! 570: for( ; i<8 ; ++i) ! 571: { ! 572: *t++ = '0'; ! 573: *t++ = ','; ! 574: } ! 575: #endif ! 576: ! 577: ! 578: sprintf(t, "0%o,0,0%o,%s", code, type, (loc? loc : "0") ); ! 579: return(buff); ! 580: } ! 581: ! 582: ! 583: ! 584: prstleng(np, leng) ! 585: register Namep np; ! 586: ftnint leng; ! 587: { ! 588: #if NOTDEF /* not useful at the moment */ ! 589: ftnint iarrlen(); ! 590: ! 591: prstab( varstr(VL,np->varname), N_LENG, 0, convic(leng) ); ! 592: #endif ! 593: } ! 594: ! 595: /* type cookies for sdb */ ! 596: ! 597: #define BASIC 5 /* width of basic type */ ! 598: #define PTR 01 /* pointer */ ! 599: #define ARY 02 /* array */ ! 600: #define FTN 03 /* function */ ! 601: #define OF 2 /* shift for `ftn ary ptr of' */ ! 602: ! 603: /* ! 604: * extra table of our types to sdb's types ! 605: * our code generator is still pcc1, but sdb expects pcc2 ! 606: * to be safe, say exactly what we mean here ! 607: */ ! 608: ! 609: int sdbtypes[] = { ! 610: 0, /* TYUNKNOWN 0 */ ! 611: PTR|4, /* TYADDR 1 == ptr to int. eh? */ ! 612: 3, /* TYSHORT 2 */ ! 613: 5, /* TYLONG 3 */ ! 614: 6, /* TYREAL 4 */ ! 615: 7, /* TYDREAL 5 */ ! 616: 6, /* TYCOMPLEX 6 == float */ ! 617: 7, /* TYDCOMPLEX 7 == double */ ! 618: 5, /* TYLOGICAL 8 == long? */ ! 619: 2, /* TYCHAR 9 */ ! 620: 4, /* TYSUBR 10 == int */ ! 621: 0, /* TYERROR 11 */ ! 622: }; ! 623: ! 624: stabtype(p) ! 625: register Namep p; ! 626: { ! 627: register int type; ! 628: type = 0; ! 629: if(p->vstg == STGARG) ! 630: type = PTR; ! 631: if(p->vdim) ! 632: type = (type << OF) | ARY; ! 633: else if(p->vclass == CLPROC) ! 634: type = (type << OF) | FTN; ! 635: return ((type << BASIC) | types2[p->vtype]); ! 636: } ! 637: ! 638: ! 639: ! 640: ! 641: prcomssym(np, xp) ! 642: register Namep np; ! 643: register struct Extsym *xp; ! 644: { ! 645: char nbuf[40]; ! 646: ! 647: sprintf(nbuf, "%d", np->voffset); ! 648: prstab(varstr(VL,np->varname), N_SSYM, stabtype(np), nbuf); ! 649: } ! 650: #endif
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.