1*43225Sbostic #include "defs.h" 2*43225Sbostic 3*43225Sbostic #ifdef SDB 4*43225Sbostic # include <a.out.h> 5*43225Sbostic extern int types2[]; 6*43225Sbostic # ifndef N_SO 7*43225Sbostic # include <stab.h> 8*43225Sbostic # endif 9*43225Sbostic #endif 10*43225Sbostic 11*43225Sbostic #include "pcc.h" 12*43225Sbostic 13*43225Sbostic /* 14*43225Sbostic TAHOE - SPECIFIC ROUTINES 15*43225Sbostic */ 16*43225Sbostic 17*43225Sbostic int maxregvar = MAXREGVAR; 18*43225Sbostic int regnum[] = { 10, 9, 8, 7, 6 } ; 19*43225Sbostic 20*43225Sbostic ftnint intcon[14] = 21*43225Sbostic { 2, 2, 2, 2, 22*43225Sbostic 15, 31, 24, 56, 23*43225Sbostic -128, -128, 127, 127, 24*43225Sbostic 0x7FFF, 0x7FFFFFFF }; 25*43225Sbostic 26*43225Sbostic #if HERE == VAX || HERE == TAHOE 27*43225Sbostic /* then put in constants in hex */ 28*43225Sbostic short realcon[6][4] = 29*43225Sbostic { 30*43225Sbostic { 0x80, 0, 0, 0 }, 31*43225Sbostic { 0x80, 0, 0, 0 }, 32*43225Sbostic { 0x7FFF, 0xFFFF, 0, 0 }, 33*43225Sbostic { 0x7FFF, 0xFFFF, 0xFFFF, 0xFFFF }, 34*43225Sbostic { 0x3480, 0, 0, 0 }, 35*43225Sbostic { 0x2480, 0, 0, 0 }, 36*43225Sbostic }; 37*43225Sbostic #else 38*43225Sbostic double realcon[6] = 39*43225Sbostic { 40*43225Sbostic 2.9387358771e-39, /* 2 ** -128 */ 41*43225Sbostic 2.938735877055718800e-39, /* 2 ** -128 */ 42*43225Sbostic 1.7014117332e+38, /* 2**127 * (1 - 2**-24) */ 43*43225Sbostic 1.701411834604692250e+38, /* 2**127 * (1 - 2**-56) */ 44*43225Sbostic 5.960464e-8, /* 2 ** -24 */ 45*43225Sbostic 1.38777878078144567e-17, /* 2 ** -56 */ 46*43225Sbostic }; 47*43225Sbostic #endif 48*43225Sbostic 49*43225Sbostic /* 50*43225Sbostic * The VAX assembler has a serious and not easily fixable problem 51*43225Sbostic * with generating instructions that contain expressions of the form 52*43225Sbostic * label1-label2 where there are .align's in-between the labels. 53*43225Sbostic * Therefore, the compiler must keep track of the offsets and output 54*43225Sbostic * .space where needed. 55*43225Sbostic */ 56*43225Sbostic LOCAL int i_offset; /* initfile offset */ 57*43225Sbostic LOCAL int a_offset; /* asmfile offset */ 58*43225Sbostic 59*43225Sbostic prsave(proflab) 60*43225Sbostic int proflab; 61*43225Sbostic { 62*43225Sbostic if(profileflag) 63*43225Sbostic { 64*43225Sbostic fprintf(asmfile, "\t.align\t2\n"); 65*43225Sbostic fprintf(asmfile, "L%d:\t.long\t0\n", proflab); 66*43225Sbostic p2pi("\tpushl\t$L%d", proflab); 67*43225Sbostic p2pass("\tcallf\t$8,mcount"); 68*43225Sbostic } 69*43225Sbostic p2pi("\tsubl3\t$LF%d,fp,sp", procno); 70*43225Sbostic } 71*43225Sbostic 72*43225Sbostic goret(type) 73*43225Sbostic int type; 74*43225Sbostic { 75*43225Sbostic register int r = 0; 76*43225Sbostic switch(type) { /* from retval */ 77*43225Sbostic case TYDREAL: 78*43225Sbostic r++; 79*43225Sbostic 80*43225Sbostic case TYLOGICAL: 81*43225Sbostic case TYADDR: 82*43225Sbostic case TYSHORT: 83*43225Sbostic case TYLONG: 84*43225Sbostic case TYREAL: 85*43225Sbostic r++; 86*43225Sbostic 87*43225Sbostic case TYCHAR: 88*43225Sbostic case TYCOMPLEX: 89*43225Sbostic case TYDCOMPLEX: 90*43225Sbostic break; 91*43225Sbostic case TYSUBR: 92*43225Sbostic if (substars) r++; 93*43225Sbostic break; 94*43225Sbostic default: 95*43225Sbostic badtype("goret", type); 96*43225Sbostic } 97*43225Sbostic p2pi("\tret#%d", r); 98*43225Sbostic } 99*43225Sbostic 100*43225Sbostic /* 101*43225Sbostic * move argument slot arg1 (relative to fp) 102*43225Sbostic * to slot arg2 (relative to ARGREG) 103*43225Sbostic */ 104*43225Sbostic mvarg(type, arg1, arg2) 105*43225Sbostic int type, arg1, arg2; 106*43225Sbostic { 107*43225Sbostic p2pij("\tmovl\t%d(fp),%d(fp)", arg1+ARGOFFSET, arg2+argloc); 108*43225Sbostic } 109*43225Sbostic 110*43225Sbostic prlabel(fp, k) 111*43225Sbostic FILEP fp; 112*43225Sbostic int k; 113*43225Sbostic { 114*43225Sbostic fprintf(fp, "L%d:\n", k); 115*43225Sbostic } 116*43225Sbostic 117*43225Sbostic prconi(fp, type, n) 118*43225Sbostic FILEP fp; 119*43225Sbostic int type; 120*43225Sbostic ftnint n; 121*43225Sbostic { 122*43225Sbostic register int i; 123*43225Sbostic 124*43225Sbostic if(type == TYSHORT) 125*43225Sbostic { 126*43225Sbostic fprintf(fp, "\t.word\t%ld\n", n); 127*43225Sbostic i = SZSHORT; 128*43225Sbostic } 129*43225Sbostic else 130*43225Sbostic { 131*43225Sbostic fprintf(fp, "\t.long\t%ld\n", n); 132*43225Sbostic i = SZLONG; 133*43225Sbostic } 134*43225Sbostic if(fp == initfile) 135*43225Sbostic i_offset += i; 136*43225Sbostic else 137*43225Sbostic a_offset += i; 138*43225Sbostic } 139*43225Sbostic 140*43225Sbostic prcona(fp, a) 141*43225Sbostic FILEP fp; 142*43225Sbostic ftnint a; 143*43225Sbostic { 144*43225Sbostic fprintf(fp, "\t.long\tL%ld\n", a); 145*43225Sbostic if(fp == initfile) 146*43225Sbostic i_offset += SZLONG; 147*43225Sbostic else 148*43225Sbostic a_offset += SZLONG; 149*43225Sbostic } 150*43225Sbostic 151*43225Sbostic prconr(fp, type, x) 152*43225Sbostic FILEP fp; 153*43225Sbostic int type; 154*43225Sbostic double x; 155*43225Sbostic { 156*43225Sbostic /* 157*43225Sbostic fprintf(fp, "\t%s\t0f%e\n", (type==TYREAL ? ".float" : ".double"), x); 158*43225Sbostic */ 159*43225Sbostic /* non-portable cheat to preserve bit patterns */ 160*43225Sbostic /* this code should be the same for PDP, VAX and Tahoe */ 161*43225Sbostic 162*43225Sbostic register struct sh4 { 163*43225Sbostic unsigned short sh[4]; 164*43225Sbostic } *cheat; 165*43225Sbostic register int i; 166*43225Sbostic 167*43225Sbostic cheat = (struct sh4 *)&x; 168*43225Sbostic if(type == TYREAL) { /* force rounding */ 169*43225Sbostic float f; 170*43225Sbostic f = x; 171*43225Sbostic x = f; 172*43225Sbostic } 173*43225Sbostic fprintf(fp, " .long 0x%04x%04x", cheat->sh[0], cheat->sh[1]); 174*43225Sbostic if(type == TYDREAL) { 175*43225Sbostic fprintf(fp, ", 0x%04x%04x", cheat->sh[2], cheat->sh[3]); 176*43225Sbostic fprintf(fp, " # .double %.17g\n", x); 177*43225Sbostic i = SZDOUBLE; 178*43225Sbostic } 179*43225Sbostic else 180*43225Sbostic { 181*43225Sbostic fprintf(fp, " # .float %.8g\n", x); 182*43225Sbostic i = SZFLOAT; 183*43225Sbostic } 184*43225Sbostic if(fp == initfile) 185*43225Sbostic i_offset += i; 186*43225Sbostic else 187*43225Sbostic a_offset += i; 188*43225Sbostic } 189*43225Sbostic 190*43225Sbostic praddr(fp, stg, varno, offset) 191*43225Sbostic FILE *fp; 192*43225Sbostic int stg, varno; 193*43225Sbostic ftnint offset; 194*43225Sbostic { 195*43225Sbostic char *memname(); 196*43225Sbostic 197*43225Sbostic if(stg == STGNULL) 198*43225Sbostic fprintf(fp, "\t.long\t0\n"); 199*43225Sbostic else 200*43225Sbostic { 201*43225Sbostic fprintf(fp, "\t.long\t%s", memname(stg,varno)); 202*43225Sbostic if(offset) 203*43225Sbostic fprintf(fp, "+%ld", offset); 204*43225Sbostic fprintf(fp, "\n"); 205*43225Sbostic } 206*43225Sbostic if(fp == initfile) 207*43225Sbostic i_offset += SZADDR; 208*43225Sbostic else 209*43225Sbostic a_offset += SZADDR; 210*43225Sbostic } 211*43225Sbostic pralign(k) 212*43225Sbostic int k; 213*43225Sbostic { 214*43225Sbostic register int lg; 215*43225Sbostic 216*43225Sbostic if (k > 4) 217*43225Sbostic lg = 3; 218*43225Sbostic else if (k > 2) 219*43225Sbostic lg = 2; 220*43225Sbostic else if (k > 1) 221*43225Sbostic lg = 1; 222*43225Sbostic else 223*43225Sbostic return; 224*43225Sbostic fprintf(initfile, "\t.align\t%d\n", lg); 225*43225Sbostic i_offset += lg; 226*43225Sbostic return; 227*43225Sbostic } 228*43225Sbostic 229*43225Sbostic 230*43225Sbostic 231*43225Sbostic prspace(n) 232*43225Sbostic int n; 233*43225Sbostic { 234*43225Sbostic 235*43225Sbostic fprintf(initfile, "\t.space\t%d\n", n); 236*43225Sbostic i_offset += n; 237*43225Sbostic } 238*43225Sbostic 239*43225Sbostic 240*43225Sbostic preven(k) 241*43225Sbostic int k; 242*43225Sbostic { 243*43225Sbostic register int lg; 244*43225Sbostic 245*43225Sbostic if(k > 4) 246*43225Sbostic lg = 3; 247*43225Sbostic else if(k > 2) 248*43225Sbostic lg = 2; 249*43225Sbostic else if(k > 1) 250*43225Sbostic lg = 1; 251*43225Sbostic else 252*43225Sbostic return; 253*43225Sbostic fprintf(asmfile, "\t.align\t%d\n", lg); 254*43225Sbostic a_offset += lg; 255*43225Sbostic } 256*43225Sbostic 257*43225Sbostic praspace(n) 258*43225Sbostic int n; 259*43225Sbostic { 260*43225Sbostic 261*43225Sbostic fprintf(asmfile, "\t.space\t%d\n", n); 262*43225Sbostic a_offset += n; 263*43225Sbostic } 264*43225Sbostic 265*43225Sbostic 266*43225Sbostic casegoto(index, nlab, labs) 267*43225Sbostic expptr index; 268*43225Sbostic register int nlab; 269*43225Sbostic struct Labelblock *labs[]; 270*43225Sbostic { 271*43225Sbostic register int i; 272*43225Sbostic register int arrlab; 273*43225Sbostic 274*43225Sbostic putforce(TYINT, index); 275*43225Sbostic p2pi("\tcasel\tr0,$1,$%d\n\t.align 1", nlab-1); 276*43225Sbostic p2pi("L%d:", arrlab = newlabel() ); 277*43225Sbostic for(i = 0; i< nlab ; ++i) 278*43225Sbostic if( labs[i] ) 279*43225Sbostic p2pij("\t.word\tL%d-L%d", labs[i]->labelno, arrlab); 280*43225Sbostic } 281*43225Sbostic 282*43225Sbostic 283*43225Sbostic prarif(p, neg, zer, pos) 284*43225Sbostic expptr p; 285*43225Sbostic int neg, zer, pos; 286*43225Sbostic { 287*43225Sbostic putforce(p->headblock.vtype, p); 288*43225Sbostic p2pass("\ttstl\tr0"); 289*43225Sbostic p2pi("\tjlss\tL%d", neg); 290*43225Sbostic p2pi("\tjeql\tL%d", zer); 291*43225Sbostic p2pi("\tjbr\tL%d", pos); 292*43225Sbostic } 293*43225Sbostic 294*43225Sbostic char *memname(stg, mem) 295*43225Sbostic int stg, mem; 296*43225Sbostic { 297*43225Sbostic static char s[20]; 298*43225Sbostic 299*43225Sbostic switch(stg) 300*43225Sbostic { 301*43225Sbostic case STGEXT: 302*43225Sbostic case STGINTR: 303*43225Sbostic if(extsymtab[mem].extname[0] == '@') { /* function opcodes */ 304*43225Sbostic strcpy(s, varstr(XL, extsymtab[mem].extname)); 305*43225Sbostic break; 306*43225Sbostic } 307*43225Sbostic case STGCOMMON: 308*43225Sbostic sprintf(s, "_%s", varstr(XL, extsymtab[mem].extname) ); 309*43225Sbostic break; 310*43225Sbostic 311*43225Sbostic case STGBSS: 312*43225Sbostic case STGINIT: 313*43225Sbostic sprintf(s, "v.%d", mem); 314*43225Sbostic break; 315*43225Sbostic 316*43225Sbostic case STGCONST: 317*43225Sbostic sprintf(s, "L%d", mem); 318*43225Sbostic break; 319*43225Sbostic 320*43225Sbostic case STGEQUIV: 321*43225Sbostic sprintf(s, "q.%d", mem+eqvstart); 322*43225Sbostic break; 323*43225Sbostic 324*43225Sbostic default: 325*43225Sbostic badstg("memname", stg); 326*43225Sbostic } 327*43225Sbostic return(s); 328*43225Sbostic } 329*43225Sbostic 330*43225Sbostic prlocvar(s, len) 331*43225Sbostic char *s; 332*43225Sbostic ftnint len; 333*43225Sbostic { 334*43225Sbostic int sz; 335*43225Sbostic sz = len; 336*43225Sbostic if (sz % SZINT) 337*43225Sbostic sz += SZINT - (sz % SZINT); 338*43225Sbostic fprintf(asmfile, "\t.lcomm\t%s,%ld\n", s, sz); 339*43225Sbostic } 340*43225Sbostic 341*43225Sbostic char * 342*43225Sbostic packbytes(cp) 343*43225Sbostic register Constp cp; 344*43225Sbostic { 345*43225Sbostic #if HERE == VAX 346*43225Sbostic static char shrt[16]; 347*43225Sbostic static char lng[4]; 348*43225Sbostic #endif 349*43225Sbostic 350*43225Sbostic switch (cp->vtype) 351*43225Sbostic { 352*43225Sbostic #if HERE == TAHOE 353*43225Sbostic case TYSHORT: 354*43225Sbostic { static short shrt; 355*43225Sbostic shrt = cp->const.ci; 356*43225Sbostic return ((char *)&shrt); 357*43225Sbostic } 358*43225Sbostic case TYLONG: 359*43225Sbostic case TYLOGICAL: 360*43225Sbostic case TYREAL: 361*43225Sbostic case TYDREAL: 362*43225Sbostic case TYDCOMPLEX: 363*43225Sbostic return ((char *)&cp->const); 364*43225Sbostic case TYCOMPLEX: 365*43225Sbostic { static float quad[2]; 366*43225Sbostic quad[0] = cp->const.cd[0]; 367*43225Sbostic quad[1] = cp->const.cd[1]; 368*43225Sbostic return ((char *)quad); 369*43225Sbostic } 370*43225Sbostic #endif 371*43225Sbostic 372*43225Sbostic #if HERE == VAX 373*43225Sbostic case TYLONG: 374*43225Sbostic case TYLOGICAL: 375*43225Sbostic swab4((char *)&cp->const.ci, lng, 4); 376*43225Sbostic return (lng); 377*43225Sbostic 378*43225Sbostic case TYSHORT: 379*43225Sbostic case TYREAL: 380*43225Sbostic case TYDREAL: 381*43225Sbostic case TYDCOMPLEX: 382*43225Sbostic swab((char *)cp->const.cd, shrt, typesize[cp->vtype]); 383*43225Sbostic return (shrt); 384*43225Sbostic case TYCOMPLEX: 385*43225Sbostic swab((char *)cp->const.cd, shrt, 4); 386*43225Sbostic swab((char *)&(cp->const.cd[1]), &shrt[4], 4); 387*43225Sbostic return (shrt); 388*43225Sbostic #endif 389*43225Sbostic 390*43225Sbostic default: 391*43225Sbostic badtype("packbytes", cp->vtype); 392*43225Sbostic } 393*43225Sbostic } 394*43225Sbostic 395*43225Sbostic #if HERE == VAX 396*43225Sbostic /* correct the byte order in longs */ 397*43225Sbostic LOCAL swab4(from, to, n) 398*43225Sbostic register char *to, *from; 399*43225Sbostic register int n; 400*43225Sbostic { 401*43225Sbostic while(n >= 4) { 402*43225Sbostic *to++ = from[3]; 403*43225Sbostic *to++ = from[2]; 404*43225Sbostic *to++ = from[1]; 405*43225Sbostic *to++ = from[0]; 406*43225Sbostic from += 4; 407*43225Sbostic n -= 4; 408*43225Sbostic } 409*43225Sbostic while(n >= 2) { 410*43225Sbostic *to++ = from[1]; 411*43225Sbostic *to++ = from[0]; 412*43225Sbostic from += 2; 413*43225Sbostic n -= 2; 414*43225Sbostic } 415*43225Sbostic if(n > 0) 416*43225Sbostic *to = *from; 417*43225Sbostic } 418*43225Sbostic #endif 419*43225Sbostic 420*43225Sbostic prsdata(s, len) 421*43225Sbostic register char *s; /* must be aligned if HERE==TAHOE */ 422*43225Sbostic register int len; 423*43225Sbostic { 424*43225Sbostic static char longfmt[] = "\t.long\t0x%x\n"; 425*43225Sbostic static char wordfmt[] = "\t.word\t0x%x\n"; 426*43225Sbostic static char bytefmt[] = "\t.byte\t0x%x\n"; 427*43225Sbostic 428*43225Sbostic register int i; 429*43225Sbostic #if HERE == VAX 430*43225Sbostic char quad[8]; 431*43225Sbostic swab4(s, quad, len); 432*43225Sbostic s = quad; 433*43225Sbostic #endif 434*43225Sbostic 435*43225Sbostic i = 0; 436*43225Sbostic if ((len - i) >= 4) 437*43225Sbostic { 438*43225Sbostic fprintf(initfile, longfmt, *((int *) s)); 439*43225Sbostic i += 4; 440*43225Sbostic } 441*43225Sbostic if ((len - i) >= 2) 442*43225Sbostic { 443*43225Sbostic fprintf(initfile, wordfmt, 0xffff & (*((short *) (s + i)))); 444*43225Sbostic i += 2; 445*43225Sbostic } 446*43225Sbostic if ((len - i) > 0) 447*43225Sbostic fprintf(initfile,bytefmt, 0xff & s[i]); 448*43225Sbostic 449*43225Sbostic i_offset += len; 450*43225Sbostic return; 451*43225Sbostic } 452*43225Sbostic 453*43225Sbostic prquad(s) 454*43225Sbostic register long *s; 455*43225Sbostic { 456*43225Sbostic static char quadfmt1[] = "\t.quad\t0x%x\n"; 457*43225Sbostic static char quadfmt2[] = "\t.quad\t0x%x%08x\n"; 458*43225Sbostic #if HERE == VAX 459*43225Sbostic char quad[8]; 460*43225Sbostic swab4((char *)s, quad, 8); 461*43225Sbostic s = (long *)quad; 462*43225Sbostic #endif 463*43225Sbostic 464*43225Sbostic if (s[0] == 0 ) 465*43225Sbostic fprintf(initfile, quadfmt1, s[1]); 466*43225Sbostic else 467*43225Sbostic fprintf(initfile, quadfmt2, s[0], s[1]); 468*43225Sbostic 469*43225Sbostic return; 470*43225Sbostic } 471*43225Sbostic 472*43225Sbostic #ifdef UCBVAXASM 473*43225Sbostic prfill(n, s) 474*43225Sbostic int n; 475*43225Sbostic register long *s; 476*43225Sbostic { 477*43225Sbostic static char fillfmt1[] = "\t.fill\t%d,8,0x%x\n"; 478*43225Sbostic static char fillfmt2[] = "\t.fill\t%d,8,0x%x%08x\n"; 479*43225Sbostic #if HERE == VAX 480*43225Sbostic char quad[8]; 481*43225Sbostic swab4((char *)s, quad, 8); 482*43225Sbostic s = (long *)quad; 483*43225Sbostic #endif 484*43225Sbostic 485*43225Sbostic if (s[0] == 0 ) 486*43225Sbostic fprintf(initfile, fillfmt1, n, s[1]); 487*43225Sbostic else 488*43225Sbostic fprintf(initfile, fillfmt2, n, s[0], s[1]); 489*43225Sbostic 490*43225Sbostic return; 491*43225Sbostic } 492*43225Sbostic #endif 493*43225Sbostic 494*43225Sbostic prext(ep) 495*43225Sbostic register struct Extsym *ep; 496*43225Sbostic { 497*43225Sbostic static char globlfmt[] = "\t.globl\t_%s\n"; 498*43225Sbostic static char commfmt[] = "\t.comm\t_%s,%ld\n"; 499*43225Sbostic static char align2fmt[] = "\t.align\t2\n"; 500*43225Sbostic static char labelfmt[] = "_%s:\n"; 501*43225Sbostic 502*43225Sbostic static char seekerror[] = "seek error on tmp file"; 503*43225Sbostic static char readerror[] = "read error on tmp file"; 504*43225Sbostic 505*43225Sbostic char *tag; 506*43225Sbostic register int leng; 507*43225Sbostic long pos; 508*43225Sbostic register char *p; 509*43225Sbostic long oldvalue[2]; 510*43225Sbostic long newvalue[2]; 511*43225Sbostic register int n; 512*43225Sbostic register int repl; 513*43225Sbostic 514*43225Sbostic tag = varstr(XL, ep->extname); 515*43225Sbostic leng = ep->maxleng; 516*43225Sbostic 517*43225Sbostic if (leng == 0) 518*43225Sbostic { 519*43225Sbostic if(*tag != '@') /* function opcodes */ 520*43225Sbostic fprintf(asmfile, globlfmt, tag); 521*43225Sbostic return; 522*43225Sbostic } 523*43225Sbostic 524*43225Sbostic if (ep->init == NO) 525*43225Sbostic { 526*43225Sbostic fprintf(asmfile, commfmt, tag, leng); 527*43225Sbostic return; 528*43225Sbostic } 529*43225Sbostic 530*43225Sbostic fprintf(asmfile, globlfmt, tag); 531*43225Sbostic fprintf(initfile, align2fmt); 532*43225Sbostic fprintf(initfile, labelfmt, tag); 533*43225Sbostic 534*43225Sbostic pos = lseek(cdatafile, ep->initoffset, 0); 535*43225Sbostic if (pos == -1) 536*43225Sbostic { 537*43225Sbostic err(seekerror); 538*43225Sbostic done(1); 539*43225Sbostic } 540*43225Sbostic 541*43225Sbostic oldvalue[0] = 0; 542*43225Sbostic oldvalue[1] = 0; 543*43225Sbostic n = read(cdatafile, oldvalue, 8); 544*43225Sbostic if (n < 0) 545*43225Sbostic { 546*43225Sbostic err(readerror); 547*43225Sbostic done(1); 548*43225Sbostic } 549*43225Sbostic 550*43225Sbostic if (leng <= 8) 551*43225Sbostic { 552*43225Sbostic p = (char *)oldvalue + leng; 553*43225Sbostic while (p > (char *)oldvalue && *--p == '\0') /* SKIP */; 554*43225Sbostic if (*p == '\0') 555*43225Sbostic prspace(leng); 556*43225Sbostic else if (leng == 8) 557*43225Sbostic prquad(oldvalue); 558*43225Sbostic else 559*43225Sbostic prsdata(oldvalue, leng); 560*43225Sbostic 561*43225Sbostic return; 562*43225Sbostic } 563*43225Sbostic 564*43225Sbostic repl = 1; 565*43225Sbostic leng -= 8; 566*43225Sbostic 567*43225Sbostic while (leng >= 8) 568*43225Sbostic { 569*43225Sbostic newvalue[0] = 0; 570*43225Sbostic newvalue[1] = 0; 571*43225Sbostic 572*43225Sbostic n = read(cdatafile, newvalue, 8); 573*43225Sbostic if (n < 0) 574*43225Sbostic { 575*43225Sbostic err(readerror); 576*43225Sbostic done(1); 577*43225Sbostic } 578*43225Sbostic 579*43225Sbostic leng -= 8; 580*43225Sbostic 581*43225Sbostic if (oldvalue[0] == newvalue[0] 582*43225Sbostic && oldvalue[1] == newvalue[1]) 583*43225Sbostic repl++; 584*43225Sbostic else 585*43225Sbostic { 586*43225Sbostic if (oldvalue[0] == 0 587*43225Sbostic && oldvalue[1] == 0) 588*43225Sbostic prspace(8*repl); 589*43225Sbostic else if (repl == 1) 590*43225Sbostic prquad(oldvalue); 591*43225Sbostic else 592*43225Sbostic #ifdef UCBVAXASM 593*43225Sbostic prfill(repl, oldvalue); 594*43225Sbostic #else 595*43225Sbostic { 596*43225Sbostic while (repl-- > 0) 597*43225Sbostic prquad(oldvalue); 598*43225Sbostic } 599*43225Sbostic #endif 600*43225Sbostic oldvalue[0] = newvalue[0]; 601*43225Sbostic oldvalue[1] = newvalue[1]; 602*43225Sbostic repl = 1; 603*43225Sbostic } 604*43225Sbostic } 605*43225Sbostic 606*43225Sbostic newvalue[0] = 0; 607*43225Sbostic newvalue[1] = 0; 608*43225Sbostic 609*43225Sbostic if (leng > 0) 610*43225Sbostic { 611*43225Sbostic n = read(cdatafile, newvalue, leng); 612*43225Sbostic if (n < 0) 613*43225Sbostic { 614*43225Sbostic err(readerror); 615*43225Sbostic done(1); 616*43225Sbostic } 617*43225Sbostic } 618*43225Sbostic 619*43225Sbostic if (oldvalue[1] == 0 620*43225Sbostic && oldvalue[0] == 0 621*43225Sbostic && newvalue[1] == 0 622*43225Sbostic && newvalue[0] == 0) 623*43225Sbostic { 624*43225Sbostic prspace(8*repl + leng); 625*43225Sbostic return; 626*43225Sbostic } 627*43225Sbostic 628*43225Sbostic if (oldvalue[1] == 0 629*43225Sbostic && oldvalue[0] == 0) 630*43225Sbostic prspace(8*repl); 631*43225Sbostic else if (repl == 1) 632*43225Sbostic prquad(oldvalue); 633*43225Sbostic else 634*43225Sbostic #ifdef UCBVAXASM 635*43225Sbostic prfill(repl, oldvalue); 636*43225Sbostic #else 637*43225Sbostic { 638*43225Sbostic while (repl-- > 0) 639*43225Sbostic prquad(oldvalue); 640*43225Sbostic } 641*43225Sbostic #endif 642*43225Sbostic 643*43225Sbostic prsdata(newvalue, leng); 644*43225Sbostic 645*43225Sbostic return; 646*43225Sbostic } 647*43225Sbostic 648*43225Sbostic prlocdata(sname, leng, type, initoffset, inlcomm) 649*43225Sbostic char *sname; 650*43225Sbostic ftnint leng; 651*43225Sbostic int type; 652*43225Sbostic long initoffset; 653*43225Sbostic char *inlcomm; 654*43225Sbostic { 655*43225Sbostic static char seekerror[] = "seek error on tmp file"; 656*43225Sbostic static char readerror[] = "read error on tmp file"; 657*43225Sbostic 658*43225Sbostic static char labelfmt[] = "%s:\n"; 659*43225Sbostic 660*43225Sbostic register int k; 661*43225Sbostic register char *p; 662*43225Sbostic register int repl; 663*43225Sbostic register int first; 664*43225Sbostic register long pos; 665*43225Sbostic register long n; 666*43225Sbostic long oldvalue[2]; 667*43225Sbostic long newvalue[2]; 668*43225Sbostic 669*43225Sbostic *inlcomm = NO; 670*43225Sbostic 671*43225Sbostic k = leng; 672*43225Sbostic first = YES; 673*43225Sbostic 674*43225Sbostic pos = lseek(vdatafile, initoffset, 0); 675*43225Sbostic if (pos == -1) 676*43225Sbostic { 677*43225Sbostic err(seekerror); 678*43225Sbostic done(1); 679*43225Sbostic } 680*43225Sbostic 681*43225Sbostic oldvalue[0] = 0; 682*43225Sbostic oldvalue[1] = 0; 683*43225Sbostic n = read(vdatafile, oldvalue, 8); 684*43225Sbostic if (n < 0) 685*43225Sbostic { 686*43225Sbostic err(readerror); 687*43225Sbostic done(1); 688*43225Sbostic } 689*43225Sbostic 690*43225Sbostic if (k <= 8) 691*43225Sbostic { 692*43225Sbostic p = (char *)oldvalue + k; 693*43225Sbostic while (p > (char *)oldvalue && *--p == '\0') 694*43225Sbostic /* SKIP */ ; 695*43225Sbostic if (*p == '\0') 696*43225Sbostic { 697*43225Sbostic if (SMALLVAR(leng)) 698*43225Sbostic { 699*43225Sbostic pralign(typealign[type]); 700*43225Sbostic fprintf(initfile, labelfmt, sname); 701*43225Sbostic prspace(leng); 702*43225Sbostic } 703*43225Sbostic else 704*43225Sbostic { 705*43225Sbostic preven(ALIDOUBLE); 706*43225Sbostic prlocvar(sname, leng); 707*43225Sbostic *inlcomm = YES; 708*43225Sbostic } 709*43225Sbostic } 710*43225Sbostic else 711*43225Sbostic { 712*43225Sbostic fprintf(initfile, labelfmt, sname); 713*43225Sbostic if (leng == 8) 714*43225Sbostic prquad(oldvalue); 715*43225Sbostic else 716*43225Sbostic prsdata(oldvalue, leng); 717*43225Sbostic } 718*43225Sbostic return; 719*43225Sbostic } 720*43225Sbostic 721*43225Sbostic repl = 1; 722*43225Sbostic k -= 8; 723*43225Sbostic 724*43225Sbostic while (k >=8) 725*43225Sbostic { 726*43225Sbostic newvalue[0] = 0; 727*43225Sbostic newvalue[1] = 0; 728*43225Sbostic 729*43225Sbostic n = read(vdatafile, newvalue, 8); 730*43225Sbostic if (n < 0) 731*43225Sbostic { 732*43225Sbostic err(readerror); 733*43225Sbostic done(1); 734*43225Sbostic } 735*43225Sbostic 736*43225Sbostic k -= 8; 737*43225Sbostic 738*43225Sbostic if (oldvalue[0] == newvalue[0] 739*43225Sbostic && oldvalue[1] == newvalue[1]) 740*43225Sbostic repl++; 741*43225Sbostic else 742*43225Sbostic { 743*43225Sbostic if (first == YES) 744*43225Sbostic { 745*43225Sbostic pralign(typealign[type]); 746*43225Sbostic fprintf(initfile, labelfmt, sname); 747*43225Sbostic first = NO; 748*43225Sbostic } 749*43225Sbostic 750*43225Sbostic if (oldvalue[0] == 0 751*43225Sbostic && oldvalue[1] == 0) 752*43225Sbostic prspace(8*repl); 753*43225Sbostic else 754*43225Sbostic { 755*43225Sbostic while (repl-- > 0) 756*43225Sbostic prquad(oldvalue); 757*43225Sbostic } 758*43225Sbostic oldvalue[0] = newvalue[0]; 759*43225Sbostic oldvalue[1] = newvalue[1]; 760*43225Sbostic repl = 1; 761*43225Sbostic } 762*43225Sbostic } 763*43225Sbostic 764*43225Sbostic newvalue[0] = 0; 765*43225Sbostic newvalue[1] = 0; 766*43225Sbostic 767*43225Sbostic if (k > 0) 768*43225Sbostic { 769*43225Sbostic n = read(vdatafile, newvalue, k); 770*43225Sbostic if (n < 0) 771*43225Sbostic { 772*43225Sbostic err(readerror); 773*43225Sbostic done(1); 774*43225Sbostic } 775*43225Sbostic } 776*43225Sbostic 777*43225Sbostic if (oldvalue[1] == 0 778*43225Sbostic && oldvalue[0] == 0 779*43225Sbostic && newvalue[1] == 0 780*43225Sbostic && newvalue[0] == 0) 781*43225Sbostic { 782*43225Sbostic if (first == YES && !SMALLVAR(leng)) 783*43225Sbostic { 784*43225Sbostic prlocvar(sname, leng); 785*43225Sbostic *inlcomm = YES; 786*43225Sbostic } 787*43225Sbostic else 788*43225Sbostic { 789*43225Sbostic if (first == YES) 790*43225Sbostic { 791*43225Sbostic pralign(typealign[type]); 792*43225Sbostic fprintf(initfile, labelfmt, sname); 793*43225Sbostic } 794*43225Sbostic prspace(8*repl + k); 795*43225Sbostic } 796*43225Sbostic return; 797*43225Sbostic } 798*43225Sbostic 799*43225Sbostic if (first == YES) 800*43225Sbostic { 801*43225Sbostic pralign(typealign[type]); 802*43225Sbostic fprintf(initfile, labelfmt, sname); 803*43225Sbostic } 804*43225Sbostic 805*43225Sbostic if (oldvalue[1] == 0 806*43225Sbostic && oldvalue[0] == 0) 807*43225Sbostic prspace(8*repl); 808*43225Sbostic else 809*43225Sbostic { 810*43225Sbostic while (repl-- > 0) 811*43225Sbostic prquad(oldvalue); 812*43225Sbostic } 813*43225Sbostic 814*43225Sbostic prsdata(newvalue, k); 815*43225Sbostic 816*43225Sbostic return; 817*43225Sbostic } 818*43225Sbostic 819*43225Sbostic prendproc() 820*43225Sbostic { 821*43225Sbostic } 822*43225Sbostic 823*43225Sbostic prtail() 824*43225Sbostic { 825*43225Sbostic } 826*43225Sbostic 827*43225Sbostic prolog(ep, argvec) 828*43225Sbostic struct Entrypoint *ep; 829*43225Sbostic Addrp argvec; 830*43225Sbostic { 831*43225Sbostic int i, argslot, proflab; 832*43225Sbostic int size; 833*43225Sbostic register chainp p; 834*43225Sbostic register Namep q; 835*43225Sbostic register struct Dimblock *dp; 836*43225Sbostic expptr tp; 837*43225Sbostic static char maskfmt[] = "\t.word\tLWM%d"; 838*43225Sbostic static char align1fmt[] = "\t.align\t1"; 839*43225Sbostic 840*43225Sbostic if(procclass == CLMAIN) { 841*43225Sbostic if(fudgelabel) 842*43225Sbostic { 843*43225Sbostic if(ep->entryname) { 844*43225Sbostic p2pass(align1fmt); 845*43225Sbostic p2ps("_%s:", varstr(XL, ep->entryname->extname)); 846*43225Sbostic p2pi(maskfmt, procno); 847*43225Sbostic } 848*43225Sbostic putlabel(fudgelabel); 849*43225Sbostic fudgelabel = 0; 850*43225Sbostic } 851*43225Sbostic else 852*43225Sbostic { 853*43225Sbostic p2pass(align1fmt); 854*43225Sbostic p2pass( "_MAIN_:" ); 855*43225Sbostic if(ep->entryname == NULL) 856*43225Sbostic p2pi(maskfmt, procno); 857*43225Sbostic } 858*43225Sbostic 859*43225Sbostic } else if(ep->entryname) 860*43225Sbostic if(fudgelabel) 861*43225Sbostic { 862*43225Sbostic putlabel(fudgelabel); 863*43225Sbostic fudgelabel = 0; 864*43225Sbostic } 865*43225Sbostic else 866*43225Sbostic { 867*43225Sbostic p2pass(align1fmt); 868*43225Sbostic p2ps("_%s:", varstr(XL, ep->entryname->extname)); 869*43225Sbostic p2pi(maskfmt, procno); 870*43225Sbostic prsave(newlabel()); 871*43225Sbostic } 872*43225Sbostic 873*43225Sbostic if(procclass == CLBLOCK) 874*43225Sbostic return; 875*43225Sbostic if (anylocals == YES) 876*43225Sbostic p2pi("\tmovl\t$v.%d,r11", bsslabel); 877*43225Sbostic if(argvec) 878*43225Sbostic { 879*43225Sbostic if (argvec->tag != TADDR) badtag ("prolog",argvec->tag); 880*43225Sbostic argloc = argvec->memoffset->constblock.const.ci + SZINT; 881*43225Sbostic /* first slot holds count */ 882*43225Sbostic if(proctype == TYCHAR) 883*43225Sbostic { 884*43225Sbostic mvarg(TYADDR, 0, chslot); 885*43225Sbostic mvarg(TYLENG, SZADDR, chlgslot); 886*43225Sbostic argslot = SZADDR + SZLENG; 887*43225Sbostic } 888*43225Sbostic else if( ISCOMPLEX(proctype) ) 889*43225Sbostic { 890*43225Sbostic mvarg(TYADDR, 0, cxslot); 891*43225Sbostic argslot = SZADDR; 892*43225Sbostic } 893*43225Sbostic else 894*43225Sbostic argslot = 0; 895*43225Sbostic 896*43225Sbostic for(p = ep->arglist ; p ; p =p->nextp) 897*43225Sbostic { 898*43225Sbostic q = (Namep) (p->datap); 899*43225Sbostic mvarg(TYADDR, argslot, q->vardesc.varno); 900*43225Sbostic argslot += SZADDR; 901*43225Sbostic } 902*43225Sbostic for(p = ep->arglist ; p ; p = p->nextp) 903*43225Sbostic { 904*43225Sbostic q = (Namep) (p->datap); 905*43225Sbostic if(q->vtype==TYCHAR && q->vclass!=CLPROC) 906*43225Sbostic { 907*43225Sbostic if(q->vleng && ! ISCONST(q->vleng) ) 908*43225Sbostic mvarg(TYLENG, argslot, 909*43225Sbostic q->vleng->addrblock.memno); 910*43225Sbostic argslot += SZLENG; 911*43225Sbostic } 912*43225Sbostic } 913*43225Sbostic if ((ep->enamep->vtype == TYCOMPLEX) && (!ep->arglist)) 914*43225Sbostic p2pass("\tmovl\tfp,r12"); 915*43225Sbostic else 916*43225Sbostic p2pi("\tsubl3\t$%d,fp,r12", ARGOFFSET-argloc); 917*43225Sbostic } else 918*43225Sbostic if((ep->arglist) || (ISCOMPLEX(proctype)) || (proctype == TYCHAR)) 919*43225Sbostic p2pass("\tmovl\tfp,r12"); 920*43225Sbostic 921*43225Sbostic for(p = ep->arglist ; p ; p = p->nextp) 922*43225Sbostic { 923*43225Sbostic q = (Namep) (p->datap); 924*43225Sbostic if(dp = q->vdim) 925*43225Sbostic { 926*43225Sbostic for(i = 0 ; i < dp->ndim ; ++i) 927*43225Sbostic if(dp->dims[i].dimexpr) 928*43225Sbostic puteq( fixtype(cpexpr(dp->dims[i].dimsize)), 929*43225Sbostic fixtype(cpexpr(dp->dims[i].dimexpr))); 930*43225Sbostic #ifdef SDB 931*43225Sbostic if(sdbflag) { 932*43225Sbostic for(i = 0 ; i < dp->ndim ; ++i) { 933*43225Sbostic if(dp->dims[i].lbaddr) 934*43225Sbostic puteq( fixtype(cpexpr(dp->dims[i].lbaddr)), 935*43225Sbostic fixtype(cpexpr(dp->dims[i].lb))); 936*43225Sbostic if(dp->dims[i].ubaddr) 937*43225Sbostic puteq( fixtype(cpexpr(dp->dims[i].ubaddr)), 938*43225Sbostic fixtype(cpexpr(dp->dims[i].ub))); 939*43225Sbostic 940*43225Sbostic } 941*43225Sbostic } 942*43225Sbostic #endif 943*43225Sbostic size = typesize[ q->vtype ]; 944*43225Sbostic if(q->vtype == TYCHAR) 945*43225Sbostic if( ISICON(q->vleng) ) 946*43225Sbostic size *= q->vleng->constblock.const.ci; 947*43225Sbostic else 948*43225Sbostic size = -1; 949*43225Sbostic 950*43225Sbostic /* on TAHOE, get more efficient subscripting if subscripts 951*43225Sbostic have zero-base, so fudge the argument pointers for arrays. 952*43225Sbostic Not done if array bounds are being checked. 953*43225Sbostic */ 954*43225Sbostic if(dp->basexpr) 955*43225Sbostic puteq( cpexpr(fixtype(dp->baseoffset)), 956*43225Sbostic cpexpr(fixtype(dp->basexpr))); 957*43225Sbostic #ifdef SDB 958*43225Sbostic if( (! checksubs) && (! sdbflag) ) 959*43225Sbostic #else 960*43225Sbostic if(! checksubs) 961*43225Sbostic #endif 962*43225Sbostic { 963*43225Sbostic if(dp->basexpr) 964*43225Sbostic { 965*43225Sbostic if(size > 0) 966*43225Sbostic tp = (expptr) ICON(size); 967*43225Sbostic else 968*43225Sbostic tp = (expptr) cpexpr(q->vleng); 969*43225Sbostic putforce(TYINT, 970*43225Sbostic fixtype( mkexpr(OPSTAR, tp, 971*43225Sbostic cpexpr(dp->baseoffset)) )); 972*43225Sbostic p2pi("\tsubl2\tr0,%d(r12)", 973*43225Sbostic p->datap->nameblock.vardesc.varno + 974*43225Sbostic ARGOFFSET); 975*43225Sbostic } 976*43225Sbostic else if(dp->baseoffset->constblock.const.ci != 0) 977*43225Sbostic { 978*43225Sbostic if(size > 0) 979*43225Sbostic { 980*43225Sbostic p2pij("\tsubl2\t$%ld,%d(r12)", 981*43225Sbostic dp->baseoffset->constblock.const.ci * size, 982*43225Sbostic p->datap->nameblock.vardesc.varno + 983*43225Sbostic ARGOFFSET); 984*43225Sbostic } 985*43225Sbostic else { 986*43225Sbostic putforce(TYINT, mkexpr(OPSTAR, cpexpr(dp->baseoffset), 987*43225Sbostic cpexpr(q->vleng) )); 988*43225Sbostic p2pi("\tsubl2\tr0,%d(r12)", 989*43225Sbostic p->datap->nameblock.vardesc.varno + 990*43225Sbostic ARGOFFSET); 991*43225Sbostic } 992*43225Sbostic } 993*43225Sbostic } 994*43225Sbostic } 995*43225Sbostic } 996*43225Sbostic 997*43225Sbostic if(typeaddr) 998*43225Sbostic puteq( cpexpr(typeaddr), mkaddcon(ep->typelabel) ); 999*43225Sbostic /* replace to avoid long jump problem 1000*43225Sbostic putgoto(ep->entrylabel); 1001*43225Sbostic */ 1002*43225Sbostic p2pi("\tjbr\tL%d", ep->entrylabel); 1003*43225Sbostic } 1004*43225Sbostic 1005*43225Sbostic prhead(fp) 1006*43225Sbostic FILEP fp; 1007*43225Sbostic { 1008*43225Sbostic #if FAMILY==PCC 1009*43225Sbostic p2triple(PCCF_FLBRAC, ARGREG-highregvar, procno); 1010*43225Sbostic p2word( (long) (BITSPERCHAR*autoleng) ); 1011*43225Sbostic p2flush(); 1012*43225Sbostic #endif 1013*43225Sbostic } 1014