From 5b3c350ad8937c44fedda273222f50ffda7fd0e9 Mon Sep 17 00:00:00 2001 From: "Robert R. Henry" Date: Wed, 20 Aug 1980 16:50:25 -0800 Subject: [PATCH] Catch relocation of floats and 8 byte qtys; restructure outrel SCCS-vsn: old/as.vax/as.h 4.7 SCCS-vsn: old/as.vax/ascode.c 4.5 SCCS-vsn: old/as.vax/asparse.c 4.6 SCCS-vsn: old/as.vax/assyms.c 4.5 --- usr/src/old/as.vax/as.h | 43 +++++++++++------- usr/src/old/as.vax/ascode.c | 86 ++++++++++++++++++++++-------------- usr/src/old/as.vax/asparse.c | 24 +++++----- usr/src/old/as.vax/assyms.c | 61 +++++++++++-------------- 4 files changed, 115 insertions(+), 99 deletions(-) diff --git a/usr/src/old/as.vax/as.h b/usr/src/old/as.vax/as.h index 3385af9f16..b1139c60af 100644 --- a/usr/src/old/as.vax/as.h +++ b/usr/src/old/as.vax/as.h @@ -1,5 +1,5 @@ /* Copyright (c) 1980 Regents of the University of California */ -/* "@(#)as.h 4.6 %G%" */ +/* "@(#)as.h 4.7 %G%" */ #ifdef VMS # define vax 1 # define VAX 1 @@ -98,33 +98,42 @@ #define ACCM (ACCR | ACCW) /* modify */ #define ACCI (ACCB | ACCR) /* XFC code */ -#define AMASK (ACCA | ACCR | ACCW | ACCB) /* the mask */ +#define ACCESSMASK (ACCA | ACCR | ACCW | ACCB) /* the mask */ /* - * Argument data types + * Argument data types + * Also used to tell outrel what it is relocating + * (possibly in combination with RELOC_PCREL and TYPNONE) */ -#define TYPB 0 /* byte */ -#define TYPW 1 /* word */ -#define TYPL 2 /* long */ -#define TYPQ 3 /* quad */ -#define TYPF 4 /* floating */ -#define TYPD 5 /* double floating */ +#define TYPB 0 /* byte */ +#define TYPW 1 /* word */ +#define TYPL 2 /* long */ +#define TYPQ 3 /* quad */ +#define TYPF 4 /* floating */ +#define TYPD 5 /* double floating */ +#define TYPNONE 6 /* when nothing */ +#define RELOC_PCREL 8 /* implicit argument to outrel; ==> PCREL */ #define TYPMASK 7 -/* reference types for loader */ +/* + * reference types for loader + */ #define PCREL 1 #define LEN1 2 #define LEN2 4 #define LEN4 6 #define LEN8 8 - /* - * reflen table converts between LEN* and PCREL to numbers - * of bytes. - * lgreflen table is the lg base 2 of the values in reflen. - */ - extern int reflen[]; /* reference lengths */ - extern int lgreflen[]; /* lg reference lengths */ + +extern int reflen[]; /* {LEN*+PCREL} ==> number of bytes */ +extern int lgreflen[]; /* {LEN*+PCREL} ==> lg number of bytes */ +extern int len124[]; /* {1,2,4,8} ==> {LEN1, LEN2, LEN4, LEN8} */ +extern char mod124[]; /* {1,2,4,8} ==> {bits to construct operands */ +extern int type_124[]; /* {1,2,4,8} ==> {TYPB, TYPW, TYPL, TYPQ} */ +extern int ty_NORELOC[]; /* {TYPB..TYPD} ==> {1 if relocation not OK */ +extern int ty_LEN[]; /* {TYPB..TYPD} ==> {LEN1..LEN8} */ +extern int ty_nbyte[]; /* {TYPB..TYPD} ==> {1,2,4,8} */ +extern int ty_nlg[]; /* {TYPB..TYPD} ==> lg{1,2,4,8} */ #define TMPC 7 #define HW 01 diff --git a/usr/src/old/as.vax/ascode.c b/usr/src/old/as.vax/ascode.c index 39ec4afe84..951d007f4c 100644 --- a/usr/src/old/as.vax/ascode.c +++ b/usr/src/old/as.vax/ascode.c @@ -1,9 +1,42 @@ /* Copyright (c) 1980 Regents of the University of California */ -static char sccsid[] = "@(#)ascode.c 4.4 %G%"; +static char sccsid[] = "@(#)ascode.c 4.5 %G%"; #include #include "as.h" #include "assyms.h" +/* + * Loader reference types (plust PCREL) to bytes and lg bytes + */ +/* LEN1 LEN1+PC LEN2 LEN2+PC LEN4 LEN4+PC LEN8 LEN8+PC*/ +int reflen[] = /* {LEN*+PCREL} ==> number of bytes */ +{0, 0, 1, 1, 2, 2, 4, 4, 8, 8}; +int lgreflen[] = /* {LEN*+PCREL} ==> lg number of bytes */ +{-1, -1, 0, 0, 1, 1, 2, 2, 3, 3}; + +/* + * Sizes to Loader reference types and type flags + */ +/*0 1 2 3 4 5 6 7 8*/ +int len124[] = /* {1,2,4,8} ==> {LEN1, LEN2, LEN4, LEN8} */ +{0, LEN1, LEN2, 0, LEN4, 0, 0, 0, LEN8}; +char mod124[] = /* {1,2,4,8} ==> {bits to construct operands */ +{0, 0x00, 0x20, 0, 0x40, 0, 0, 0, 0}; +int type_124[] = /* {1,2,4,8} ==> {TYPB, TYPW, TYPL, TYPQ} */ +{0, TYPB, TYPW, 0, TYPL, 0, 0, 0, TYPQ}; + +/* + * type flags to Loader reference and byte lengths + */ +/*TYPB TYPW TYPL TYPQ TYPF TYPD*/ +int ty_NORELOC[] = /* {TYPB..TYPD} ==> {1 if relocation not OK */ +{0, 0, 0, 1, 1, 1}; +int ty_LEN[] = /* {TYPB..TYPD} ==> {LEN1..LEN8} */ +{LEN1, LEN2, LEN4, LEN8, LEN4, LEN8}; +int ty_nbyte[] = /* {TYPB..TYPD} ==> {1,2,4,8} */ +{1, 2, 4, 8, 4, 8}; +int ty_nlg[] = /* {TYPB..TYPD} ==> lg{1,2,4,8} */ +{0, 1, 2, 3, 2, 3}; + insout(op, ap, nact) struct arg *ap; { @@ -29,9 +62,9 @@ insout(op, ap, nact) * Check argument compatability with instruction template */ for (ap_walk = ap, i = 1; i <= nact; ap_walk++, i++){ - ap_type = ap_walk->a_type; + ap_type = ap_walk->a_atype; ap_type_mask = ap_type & AMASK; - switch( (fetcharg(ip, i-1)) & AMASK){ /* type of fp */ + switch( (fetcharg(ip, i-1)) & ACCESSMASK){ /* type of fp */ case ACCB: if ( !((ap_type_mask == AEXP) || (ap_type_mask == AIMM)) ){ yyerror("arg %d, branch displacement must be an expression",i); @@ -68,8 +101,8 @@ insout(op, ap, nact) return; case AIMM: yyerror("arg %d, indexing a constant",i); return; - case DECR: - case INCR: if (ap_walk->a_areg1==ap_walk->a_areg2) { + case ADECR: + case AINCR: if (ap_walk->a_areg1==ap_walk->a_areg2) { yyerror("arg %d, indexing with modified register",i); return; } @@ -84,8 +117,6 @@ insout(op, ap, nact) } extern int d124; - int len124[] = {0,LEN1,LEN2,0,LEN4}; - char mod124[] = {0,0x00,0x20,0,0x40}; putins(op, ap, n) /* @@ -95,7 +126,8 @@ putins(op, ap, n) { register struct exp *xp; register int a; - int i,xtrab; + int i; + int reloc_how; #ifdef DEBUG fflush(stdout); @@ -195,7 +227,7 @@ PASS2: for (i=0; ia_atype; xp=ap->a_xp; - xtrab=0; + reloc_how = TYPNONE; if (a&AINDX) { #ifdef UNIX { outb(0x40 | ap->a_areg2); } @@ -239,33 +271,33 @@ PASS2: if (aMAXWORD) yyerror("Branch too far"); xp->e_xvalue = a>>8; - xtrab = LEN1; + reloc_how = TYPB; break; } /* reduces to expr(pc) mode */ ap->a_areg1 |= (0xAF + mod124[ap->a_dispsize]); - xtrab = len124[ap->a_dispsize]+PCREL; + reloc_how = type_124[ap->a_dispsize] + RELOC_PCREL; break; case ADISP: /* expr(%r) */ ap->a_areg1 |= 0xA0; if ((xp->e_xtype&XTYPE)!=XABS || xp->e_xtype&XFORW){ ap->a_areg1 += mod124[ap->a_dispsize]; - xtrab=len124[ap->a_dispsize]; + reloc_how = type_124[ap->a_dispsize]; break; } if (xp->e_xvalue==0 && !(ap->a_areg1&0x10)) { ap->a_areg1 ^= 0xC0; break; } - xtrab=LEN1; + reloc_how = TYPB; if ((xp->e_xvaluee_xvalue>MAXBYTE)){ ap->a_areg1 += 0x20; - xtrab=LEN2; + reloc_how = TYPW; } if ((xp->e_xvaluee_xvalue>MAXWORD)){ ap->a_areg1 += 0x20; - xtrab=LEN4; + reloc_how = TYPL; } break; @@ -290,22 +322,15 @@ PASS2: } } ap->a_areg1 |= 0x8F; - switch (a) { - case TYPD: - case TYPF: + reloc_how = a; + if (reloc_how == TYPD || reloc_how == TYPF){ if ( ((xp->e_xtype&XTYPE)==XABS) && (!(xp->e_xtype&XFORW)) && (slitflt(xp)) ){ + reloc_how = TYPNONE; ap->a_areg1=extlitflt(xp); - } else { - xtrab = (a==TYPF) ? LEN4: LEN8; } - break; - case TYPQ: xtrab = LEN8; break; - case TYPL: xtrab = LEN4; break; - case TYPW: xtrab = LEN2; break; - case TYPB: xtrab = LEN1; break; } break; @@ -324,14 +349,7 @@ PASS2: vms_obj_ptr=sobuf+1; } #endif VMS - if (xtrab) - /* - * Floating point numbers are written to a.out - * by outrel; they require that the least significant - * 4 bytes of an 8 byte double precision number - * immediately follow the field xvalue, which - * they do. - */ - outrel(&xp->e_xvalue, xtrab, xp->e_xtype, xp->e_xname); + if (reloc_how != TYPNONE) + outrel(xp, reloc_how); } /*end of the for to pick up all arguments*/ } diff --git a/usr/src/old/as.vax/asparse.c b/usr/src/old/as.vax/asparse.c index d8a8a968db..6fff6a4b70 100644 --- a/usr/src/old/as.vax/asparse.c +++ b/usr/src/old/as.vax/asparse.c @@ -1,5 +1,5 @@ /* Copyright (c) 1980 Regents of the University of California */ -static char sccsid[] = "@(#)asparse.c 4.5 %G%"; +static char sccsid[] = "@(#)asparse.c 4.6 %G%"; #include #include "as.h" #include "asexpr.h" @@ -78,6 +78,7 @@ int yyparse() int field_value; /*the value to stuff in a field*/ char *stabname; /*name of stab dealing with*/ ptrall stabstart; /*where the stab starts in the buffer*/ + int reloc_how; /* how to relocate expressions */ xp = explist; ap = arglist; @@ -364,18 +365,15 @@ restlab: if ((locxp->e_xtype&XTYPE)!=XABS) { if (bitoff) yyerror("Illegal relocation in field"); - field_width=LEN1; - if (curlen==NBPW) - field_width = LEN4; - if (curlen==NBPW/2) - field_width = LEN2; + switch(curlen){ + case NBPW/4: reloc_how = TYPB; break; + case NBPW/2: reloc_how = TYPW; break; + case NBPW: reloc_how = TYPL; break; + } if (passno == 1){ - dotp->e_xvalue += reflen[field_width]; + dotp->e_xvalue += ty_nbyte[reloc_how]; } else { - outrel(&locxp->e_xvalue, - field_width, - locxp->e_xtype, - locxp->e_xname); + outrel(locxp, reloc_how); } } else { field_value = locxp->e_xvalue & ( (1L << field_width)-1); @@ -548,7 +546,7 @@ restlab: * final expression is taken to be the current * location counter, and is patched by the 2nd pass * - * .stab{,}*8,, , , + * .stab{,}*NCPS,, , , * .stabn , , , * .stabs STRING, , , , * .stabd , , # . @@ -567,7 +565,7 @@ restlab: (char *)stabstart -= sizeof(struct symtab *); (char *)stabstart -= sizeof(toktype); shift; - for (argcnt = 0; argcnt < 8; argcnt++){ + for (argcnt = 0; argcnt < NCPS; argcnt++){ expr(locxp, val); stpt->s_name[argcnt] = locxp->e_xvalue; xp = explist; diff --git a/usr/src/old/as.vax/assyms.c b/usr/src/old/as.vax/assyms.c index f5420ed7c5..e5a79d2a64 100644 --- a/usr/src/old/as.vax/assyms.c +++ b/usr/src/old/as.vax/assyms.c @@ -1,5 +1,5 @@ /* Copyright (c) 1980 Regents of the University of California */ -static char sccsid[] = "@(#)assyms.c 4.4 %G%"; +static char sccsid[] = "@(#)assyms.c 4.5 %G%"; #include #include #include "as.h" @@ -478,14 +478,6 @@ char *savestr(str) return (res); } -/* - * The following two tables are indexed by - * {LEN1,LEN2,LEN4,LEN8} | {PCREL,0} - * Note that PCREL = 1 - */ -int reflen[] = {0, 0, 1, 1, 2, 2, 4, 4, 8, 8}; -int lgreflen[] = {-1, -1, 0, 0, 1, 1, 2, 2, 3, 3}; - /* * The relocation information is saved internally in an array of * lists of relocation buffers. The relocation buffers are @@ -521,40 +513,39 @@ initoutrel() r_can_1PC.r_pcrel = 1; } -outrel(pval,reftype,reltype,xsym) - long *pval; - register int reftype,reltype; - struct symtab *xsym; +outrel(xp, reloc_how) + register struct exp *xp; + int reloc_how; /* TYPB..TYPD + (possibly)RELOC_PCREL */ { -/* - * reftype: PCREL or not, plus length LEN1, LEN2, LEN4, LEN8 - * reltype: csect ("segment") number (XTEXT, XDATA, ...) associated with 'val' - * xsym: symbol table pointer - */ - short this_reflen; - struct relocation_info reloc; + struct relocation_info reloc; + register int x_type_mask; + int pcrel; - this_reflen = reflen[reftype]; + x_type_mask = xp->e_xtype & ~XFORW; + pcrel = reloc_how & RELOC_PCREL; + reloc_how &= ~RELOC_PCREL; + if (bitoff&07) yyerror("Padding error"); - reltype &= ~XFORW; - if (reltype == XUNDEF) + if (x_type_mask == XUNDEF) yyerror("Undefined reference"); - if (reltype != XABS || reftype & PCREL) { - reloc = (reftype & PCREL)? r_can_1PC : r_can_0PC; + if ( (x_type_mask != XABS) || pcrel ) { + if (ty_NORELOC[reloc_how]) + yyerror("Illegal Relocation of float, double or quad."); + reloc = pcrel ? r_can_1PC : r_can_0PC; reloc.r_address = dotp->e_xvalue - ( (dotp < &usedot[NLOC] || readonlydata) ? 0 : datbase ); - reloc.r_length = lgreflen[reftype]; - switch(reltype){ + reloc.r_length = ty_nlg[reloc_how]; + switch(x_type_mask){ case XXTRN | XUNDEF: - reloc.r_symbolnum = xsym->s_index; + reloc.r_symbolnum = xp->e_xname->s_index; reloc.r_extern = 1; break; default: - if (readonlydata && (reltype&~XXTRN) == XDATA) - reltype = XTEXT | (reltype&XXTRN); - reloc.r_symbolnum = reltype; + if (readonlydata && (x_type_mask&~XXTRN) == XDATA) + x_type_mask = XTEXT | (x_type_mask&XXTRN); + reloc.r_symbolnum = x_type_mask; break; } if ( (relfil == 0) || (relfil->rel_count >= NRELOC) ){ @@ -574,10 +565,10 @@ outrel(pval,reftype,reltype,xsym) /* * write the unrelocated value to the text file */ - dotp->e_xvalue += this_reflen; - if (reftype & PCREL) - *pval -= dotp->e_xvalue; - bwrite((char *)pval, this_reflen, txtfil); + dotp->e_xvalue += ty_nbyte[reloc_how]; + if (pcrel) + xp->e_xvalue -= dotp->e_xvalue; + bwrite((char *)&(xp->e_xvalue), ty_nbyte[reloc_how], txtfil); } /* * Flush out all of the relocation information. -- 2.20.1