1984-05-19 12:52:21 +00:00
|
|
|
#ifndef NORCSID
|
|
|
|
static char rcsid[] = "$Header$";
|
|
|
|
#endif
|
|
|
|
|
1984-05-19 12:48:59 +00:00
|
|
|
/*
|
1987-03-10 01:26:51 +00:00
|
|
|
* (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
|
|
|
|
* See the copyright notice in the ACK home directory, in the file "Copyright".
|
1984-05-19 12:48:59 +00:00
|
|
|
*
|
|
|
|
* Author: Hans van Staveren
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* machine dependent back end routines for the PDP-11
|
|
|
|
*/
|
|
|
|
|
1984-07-12 11:03:18 +00:00
|
|
|
/* #define REGPATCH /* save all registers in markblock */
|
1984-05-19 12:48:59 +00:00
|
|
|
|
|
|
|
con_part(sz,w) register sz; word w; {
|
|
|
|
|
|
|
|
while (part_size % sz)
|
|
|
|
part_size++;
|
1984-10-23 15:02:03 +00:00
|
|
|
if (part_size == TEM_WSIZE)
|
1984-05-19 12:48:59 +00:00
|
|
|
part_flush();
|
|
|
|
if (sz == 1) {
|
|
|
|
w &= 0xFF;
|
|
|
|
if (part_size)
|
|
|
|
w <<= 8;
|
|
|
|
part_word |= w;
|
|
|
|
} else {
|
|
|
|
assert(sz == 2);
|
|
|
|
part_word = w;
|
|
|
|
}
|
|
|
|
part_size += sz;
|
|
|
|
}
|
|
|
|
|
|
|
|
con_mult(sz) word sz; {
|
1987-02-04 15:09:31 +00:00
|
|
|
long l, atol();
|
1984-05-19 12:48:59 +00:00
|
|
|
|
|
|
|
if (sz != 4)
|
|
|
|
fatal("bad icon/ucon size");
|
1984-10-16 13:31:44 +00:00
|
|
|
#ifdef ACK_ASS
|
1987-02-04 15:09:31 +00:00
|
|
|
fprintf(codefile,".data4 %s\n",str);
|
1984-10-16 13:31:44 +00:00
|
|
|
#else
|
1984-05-19 12:48:59 +00:00
|
|
|
l = atol(str);
|
|
|
|
fprintf(codefile,"\t%o;%o\n",(int)(l>>16),(int)l);
|
1984-10-16 13:31:44 +00:00
|
|
|
#endif
|
1984-05-19 12:48:59 +00:00
|
|
|
}
|
|
|
|
|
1984-10-16 13:31:44 +00:00
|
|
|
/*
|
|
|
|
* The next function is difficult to do when not running on a PDP 11 or VAX
|
|
|
|
* The strategy followed is to assume the code generator is running on a PDP 11
|
|
|
|
* unless the ACK_ASS define is on.
|
|
|
|
*/
|
|
|
|
|
1984-05-19 12:48:59 +00:00
|
|
|
con_float() {
|
1984-10-16 13:31:44 +00:00
|
|
|
#ifdef ACK_ASS
|
1988-04-22 14:11:55 +00:00
|
|
|
double f;
|
|
|
|
double atof(), frexp();
|
1987-05-14 14:58:21 +00:00
|
|
|
int i, j;
|
|
|
|
int sign = 0;
|
|
|
|
int fraction ;
|
1984-10-16 13:31:44 +00:00
|
|
|
|
|
|
|
if (argval != 4 && argval != 8)
|
|
|
|
fatal("bad fcon size");
|
1987-05-14 14:58:21 +00:00
|
|
|
f = atof(str);
|
1987-05-15 16:32:14 +00:00
|
|
|
if (f == 0) {
|
|
|
|
if (argval == 8) fprintf(codefile, ".data2 0, 0\n");
|
|
|
|
fprintf(codefile, ".data2 0, 0\n");
|
|
|
|
return;
|
|
|
|
}
|
1988-04-20 14:42:04 +00:00
|
|
|
f = frexp(f, &i);
|
|
|
|
if (f < 0) {
|
|
|
|
f = -f;
|
|
|
|
sign = 1;
|
|
|
|
}
|
1987-05-14 14:58:21 +00:00
|
|
|
while (f < 0.5) {
|
|
|
|
f += f;
|
|
|
|
i --;
|
|
|
|
}
|
1988-04-22 14:11:55 +00:00
|
|
|
f = 2*f - 1.0; /* hidden bit */
|
1987-05-14 14:58:21 +00:00
|
|
|
i = (i + 128) & 0377;
|
|
|
|
fraction = (sign << 15) | (i << 7);
|
|
|
|
for (j = 6; j>= 0; j--) {
|
1988-04-22 14:11:55 +00:00
|
|
|
f *= 2;
|
|
|
|
if (f >= 1.0) {
|
|
|
|
fraction |= (1 << j);
|
|
|
|
f -= 1.0;
|
|
|
|
}
|
1987-05-14 14:58:21 +00:00
|
|
|
}
|
|
|
|
fprintf(codefile, ".data2 0%o", fraction);
|
|
|
|
for (i = argval / 2 - 1; i; i--) {
|
|
|
|
fraction = 0;
|
|
|
|
for (j = 15; j>= 0; j--) {
|
1988-04-22 14:11:55 +00:00
|
|
|
f *= 2;
|
|
|
|
if (f >= 1.0) {
|
|
|
|
fraction |= (1 << j);
|
|
|
|
f -= 1.0;
|
|
|
|
}
|
1987-05-14 14:58:21 +00:00
|
|
|
}
|
|
|
|
fprintf(codefile, ", 0%o", fraction);
|
|
|
|
}
|
|
|
|
putc('\n', codefile);
|
1984-10-16 13:31:44 +00:00
|
|
|
#else
|
1984-05-19 12:48:59 +00:00
|
|
|
double f;
|
1987-05-14 14:58:21 +00:00
|
|
|
double atof();
|
|
|
|
int i;
|
|
|
|
short *p;
|
1984-05-19 12:48:59 +00:00
|
|
|
|
|
|
|
if (argval != 4 && argval != 8)
|
|
|
|
fatal("bad fcon size");
|
|
|
|
f = atof(str);
|
|
|
|
p = (short *) &f;
|
|
|
|
i = *p++;
|
|
|
|
if (argval == 8) {
|
|
|
|
fprintf(codefile,"\t%o;%o;",i,*p++);
|
|
|
|
i = *p++;
|
|
|
|
}
|
|
|
|
fprintf(codefile,"\t%o;%o\n",i,*p++);
|
1984-10-16 13:31:44 +00:00
|
|
|
#endif
|
1984-05-19 12:48:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef REGVARS
|
|
|
|
|
1984-07-26 13:05:22 +00:00
|
|
|
char Rstring[10];
|
|
|
|
full lbytes;
|
|
|
|
struct regadm {
|
|
|
|
char *ra_str;
|
|
|
|
long ra_off;
|
|
|
|
} regadm[2];
|
1984-08-23 17:07:53 +00:00
|
|
|
int n_regvars;
|
1984-05-19 12:48:59 +00:00
|
|
|
|
|
|
|
regscore(off,size,typ,score,totyp) long off; {
|
|
|
|
|
|
|
|
if (size != 2)
|
|
|
|
return(-1);
|
|
|
|
score -= 1; /* allow for save/restore */
|
|
|
|
if (off>=0)
|
|
|
|
score -= 2;
|
|
|
|
if (typ==reg_pointer)
|
|
|
|
score *= 17;
|
|
|
|
else if (typ==reg_loop)
|
|
|
|
score = 10*score+50; /* Guestimate */
|
|
|
|
else
|
|
|
|
score *= 10;
|
|
|
|
return(score); /* estimated # of words of profit */
|
|
|
|
}
|
|
|
|
|
|
|
|
i_regsave() {
|
|
|
|
|
1984-07-26 13:05:22 +00:00
|
|
|
Rstring[0] = 0;
|
1984-08-23 17:07:53 +00:00
|
|
|
n_regvars=0;
|
1984-05-19 12:48:59 +00:00
|
|
|
}
|
|
|
|
|
1984-07-26 13:05:22 +00:00
|
|
|
f_regsave() {
|
|
|
|
register i;
|
|
|
|
|
1984-08-23 17:07:53 +00:00
|
|
|
if (n_regvars==0 || lbytes==0) {
|
1984-07-26 13:05:22 +00:00
|
|
|
#ifdef REGPATCH
|
|
|
|
fprintf(codefile,"mov r2,-(sp)\nmov r4,-(sp)\n");
|
|
|
|
#endif
|
|
|
|
fprintf(codefile,"mov r5,-(sp)\nmov sp,r5\n");
|
|
|
|
if (lbytes == 2)
|
|
|
|
fprintf(codefile,"tst -(sp)\n");
|
|
|
|
else if (lbytes!=0)
|
|
|
|
fprintf(codefile,"sub $0%o,sp\n",lbytes);
|
1984-08-23 17:07:53 +00:00
|
|
|
for (i=0;i<n_regvars;i++)
|
1984-07-26 13:05:22 +00:00
|
|
|
fprintf(codefile,"mov %s,-(sp)\n",regadm[i].ra_str);
|
|
|
|
} else {
|
|
|
|
if (lbytes>6) {
|
|
|
|
fprintf(codefile,"mov $0%o,r0\n",lbytes);
|
|
|
|
fprintf(codefile,"jsr r5,PR%s\n",Rstring);
|
|
|
|
} else {
|
|
|
|
fprintf(codefile,"jsr r5,PR%d%s\n",lbytes,Rstring);
|
|
|
|
}
|
|
|
|
}
|
1984-08-23 17:07:53 +00:00
|
|
|
for (i=0;i<n_regvars;i++)
|
1984-07-26 13:05:22 +00:00
|
|
|
if (regadm[i].ra_off>=0)
|
|
|
|
fprintf(codefile,"mov 0%lo(r5),%s\n",regadm[i].ra_off,
|
|
|
|
regadm[i].ra_str);
|
|
|
|
}
|
1984-05-19 12:48:59 +00:00
|
|
|
|
|
|
|
regsave(regstr,off,size) char *regstr; long off; {
|
|
|
|
|
1984-10-16 13:31:44 +00:00
|
|
|
fprintf(codefile,"%c Local %ld into %s\n",COMMENTCHAR,off,regstr);
|
1984-07-26 13:05:22 +00:00
|
|
|
/* commented away
|
1984-05-19 12:48:59 +00:00
|
|
|
#ifndef REGPATCH
|
|
|
|
fprintf(codefile,"mov %s,-(sp)\n",regstr);
|
|
|
|
#endif
|
|
|
|
strcat(Rstring,regstr);
|
|
|
|
if (off>=0)
|
|
|
|
fprintf(codefile,"mov 0%lo(r5),%s\n",off,regstr);
|
1984-07-26 13:05:22 +00:00
|
|
|
end of commented away */
|
|
|
|
|
|
|
|
strcat(Rstring,regstr);
|
1984-08-23 17:07:53 +00:00
|
|
|
regadm[n_regvars].ra_str = regstr;
|
|
|
|
regadm[n_regvars].ra_off = off;
|
|
|
|
n_regvars++;
|
1984-05-19 12:48:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
regreturn() {
|
|
|
|
|
|
|
|
#ifdef REGPATCH
|
|
|
|
fprintf(codefile,"jmp eret\n");
|
|
|
|
#else
|
1984-07-26 13:05:22 +00:00
|
|
|
fprintf(codefile,"jmp RT%s\n",Rstring);
|
1984-05-19 12:48:59 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
prolog(nlocals) full nlocals; {
|
|
|
|
|
1984-07-26 13:05:22 +00:00
|
|
|
#ifndef REGVARS
|
1984-05-19 12:48:59 +00:00
|
|
|
#ifdef REGPATCH
|
|
|
|
fprintf(codefile,"mov r2,-(sp)\nmov r4,-(sp)\n");
|
|
|
|
#endif
|
|
|
|
fprintf(codefile,"mov r5,-(sp)\nmov sp,r5\n");
|
|
|
|
if (nlocals == 0)
|
|
|
|
return;
|
|
|
|
if (nlocals == 2)
|
|
|
|
fprintf(codefile,"tst -(sp)\n");
|
|
|
|
else
|
|
|
|
fprintf(codefile,"sub $0%o,sp\n",nlocals);
|
1984-07-26 13:05:22 +00:00
|
|
|
#else
|
|
|
|
lbytes = nlocals;
|
|
|
|
#endif
|
1984-05-19 12:48:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
dlbdlb(as,ls) string as,ls; {
|
|
|
|
|
|
|
|
if (strlen(as)+strlen(ls)+2<sizeof(labstr)) {
|
|
|
|
strcat(ls,":");
|
|
|
|
strcat(ls,as);
|
|
|
|
} else
|
|
|
|
fatal("too many consecutive labels");
|
|
|
|
}
|
|
|
|
|
|
|
|
mes(type) word type; {
|
|
|
|
int argt ;
|
|
|
|
|
|
|
|
switch ( (int)type ) {
|
|
|
|
case ms_ext :
|
|
|
|
for (;;) {
|
|
|
|
switch ( argt=getarg(
|
|
|
|
ptyp(sp_cend)|ptyp(sp_pnam)|sym_ptyp) ) {
|
|
|
|
case sp_cend :
|
|
|
|
return ;
|
|
|
|
default:
|
|
|
|
strarg(argt) ;
|
1984-10-16 13:31:44 +00:00
|
|
|
#ifdef ACK_ASS
|
|
|
|
fprintf(codefile,".define %s\n",argstr) ;
|
|
|
|
#else
|
1984-05-19 12:48:59 +00:00
|
|
|
fprintf(codefile,".globl %s\n",argstr) ;
|
1984-10-16 13:31:44 +00:00
|
|
|
#endif
|
1984-05-19 12:48:59 +00:00
|
|
|
break ;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
default :
|
|
|
|
while ( getarg(any_ptyp) != sp_cend ) ;
|
|
|
|
break ;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
char *segname[] = {
|
1987-02-04 15:09:31 +00:00
|
|
|
#ifdef ACK_ASS
|
|
|
|
".sect .text", /* SEGTXT */
|
|
|
|
".sect .data", /* SEGCON */
|
|
|
|
".sect .rom", /* SEGROM */
|
|
|
|
".sect .bss" /* SEGBSS */
|
|
|
|
#else
|
1984-05-19 12:48:59 +00:00
|
|
|
".text", /* SEGTXT */
|
|
|
|
".data", /* SEGCON */
|
|
|
|
".data", /* SEGROM */
|
|
|
|
".bss" /* SEGBSS */
|
1987-02-04 15:09:31 +00:00
|
|
|
#endif
|
1984-05-19 12:48:59 +00:00
|
|
|
};
|